Matplotlib Subplot

Matplotlib Subplot

Display Multiple Plots

With the subplot() function you can draw multiple plots in one figure:

Example

Draw 2 plots:

Result:

Try it Yourself »


The subplot() Function

The subplot() function takes three arguments that describes the layout of the figure.

The layout is organized in rows and columns, which are represented by the first and second argument.

The third argument represents the index of the current plot.

So, if we want a figure with 2 rows an 1 column (meaning that the two plots will be displayed on top of each other instead of side-by-side), we can write the syntax like this:

Example

Draw 2 plots on top of each other:

Result:

Try it Yourself »

You can draw as many plots you like on one figure, just descibe the number of rows, columns, and the index of the plot.

Example

Draw 6 plots:

Result:

Try it Yourself »


Title

You can add a title to each plot with the title() function:

Example

2 plots, with titles:

Result:

Try it Yourself »


Super Title

You can add a title to the entire figure with the suptitle() function:

Example

Add a title for the entire figure:

Result:

Try it Yourself »

ArmenianEnglish