Skip to main content

Matplotlib: Subplots() Function

subplot() function is basically act as utility wrapper which is used to create multiple plot in one figure. Utility Wrapper can help in creating a common layouts of subplots and it also includes the enclosing figure object, in a single call.


plt.subplots(nrows=1, ncols=1, *, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw)


  • rows, ncols: Number of rows and columns
  • sharex, sharey: It controls sharing properties between x and y axes.
  • squeeze: It is used to squeeze out extra dimension form the returned array of axes.
  • subplot_kw: It is used to pass the dict with keywords which is used to create subplots.
  • gridspec_kw: It is used to pass the dict with keywords which is used as constructor to create a grid on which the subplots are placed.
  • **fig_kw: It has all additional keyword arguments are passed.


import matplotlib.pyplot as plt
import numpy as np 

c= np.array([1,2,4])

plt.figure() # used to create figure

#for first subplot
plt.plot(a,b, color="blue", marker="o")

# for second subplot
plt.plot(b,c, color="red", marker="*")



Submitted by devanshi.srivastava on November 24, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.