Matplotlib.pyplot.subplot() function in Python Last Updated : 20 May, 2022 Comments Improve Suggest changes Like Article Like Report Prerequisites: matplotlib subplot() function adds subplot to a current figure at the specified grid position. It is similar to the subplots() function however unlike subplots() it adds one subplot at a time. So to create multiple plots you will need several lines of code with the subplot() function. Another drawback of the subplot function is that it deletes the preexisting plot on your figure. Refer to example 1. It is a wrapper of Figure.add_subplot. Syntax: subplot(nrows, ncols, index, **kwargs) subplot(pos, **kwargs) subplot(ax) Parameters : args: Either a 3-digit integer or three separate integers describing the position of the subplot.pos is a three-digit integer where the first, second, and third integer are nrows,ncols, index.projection : [{None, ’aitoff’, ’hammer’, ’lambert’, ’mollweide’, ’polar’, ’rectilinear’, str}, optional]. The projection-type of the subplot (Axes). The default None results in a ’rectilinear’ projection.label : [str] A label for the returned axes.**kwargs: This method also takes the keyword arguments for the returned axes base class;except for the figure argument, for e.g facecolor. Returns : An axes.SubplotBase subclass of Axes or a subclass of Axes. The returned axes base class depends on the projection used. Implementation of the function is given below: Example 1: subplot() will delete the pre-existing plot. Python3 # importing the module import matplotlib.pyplot as plt # Data to display on plot x = [1, 2, 3, 4, 5] y = [1, 2, 1, 2, 1] # plot() will create new figure and will add axes object (plot) of above data plt.plot(x, y, marker="x", color="green") # subplot() will add plot to current figure deleting existing plot plt.subplot(121) Output: We can see that the first plot got set aside by the subplot() function. subplot_gfg If you want to see the first plot comment out plt.subplot() line and you will see the following plot plot_gfg Example 2: Python3 import matplotlib.pyplot as plt # data to display on plots x = [3, 1, 3] y = [3, 2, 1] z = [1, 3, 1] # Creating figure object plt.figure() # adding first subplot plt.subplot(121) plt.plot(x, y, color="orange", marker="*") # adding second subplot plt.subplot(122) plt.plot(z, y, color="yellow", marker="*") Output : multiple_subplots Comment More infoAdvertise with us Next Article Matplotlib.pyplot.subplot() function in Python T tejalkadam18m Follow Improve Article Tags : Python Python-matplotlib Matplotlib Pyplot-class Practice Tags : python Similar Reads Matplotlib.pyplot.setp() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.subplots_adjust() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.plot() function in Python The matplotlib.pyplot.plot() is used to create 2D plots such as line graphs and scatter plots. The plot() function allows us to plot data points, customize line styles, markers and colors making it useful for various types of visualizations. In this article, we'll see how to use this function to plo 3 min read Matplotlib.pyplot.subplot_tool() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 8 1 min read Matplotlib.pyplot.subplot2grid() in python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.pyplot.subplot2grid() The Matplotlib.pyplot.subplot2grid() function give addi 3 min read Matplotlib.pyplot.figimage() function in Python Matplotlib is a widely used library in Python for plotting various graphs, as it provides very efficient ways and easy to understand methods for complex plots also. pyplot is a collection of command style functions that make matplotlib work like MATLAB. figimage() function matplotlib.pyplot.figimage 2 min read Matplotlib.pyplot.triplot() in python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.gci() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.show() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code - Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 2 min read Matplotlib.pyplot.autumn() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Like