Articles → Matplotlib → Subplot Function In Matplotlib
Subplot Function In Matplotlib
Purpose
- Divides the figure into rows and columns
- Axes are created at a given position.
Syntax
Pyplot_object.subplot(m, n, p)
- ‘m’ specifies the number of rows.
- ‘n’ specifies the number of columns.
- ‘p’ specifies the position.
Example 1
import matplotlib.pyplot as plt
import array
arr1 = array.array('i', [1, 2, 3])
arr2 = array.array('i', [4, 5, 6])
plt.subplot(2,2,3)
plt.plot(arr1,arr2)
plt.show()
Example 2
import matplotlib.pyplot as plt
import array
arr1 = array.array('i', [1, 2, 3])
arr2 = array.array('i', [4, 5, 6])
plt.subplot(2,2,3)
plt.plot(arr1,arr2)
plt.subplot(2,2,4)
plt.plot(arr1,arr2)
plt.show()