Articles → Matplotlib → Subplot Function In Matplotlib

Subplot Function In Matplotlib






Purpose




  1. Divides the figure into rows and columns
  2. Axes are created at a given position.


Picture showing how the subplot function divides the figure into four quadrants





Syntax


Pyplot_object.subplot(m, n, p)




  1. ‘m’ specifies the number of rows.
  2. ‘n’ specifies the number of columns.
  3. ‘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()




Picture showing the output of the subplot function in matplotlib



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()




Picture showing the output of the subplot function in matplotlib



Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, May 28, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250