If you want to create multiple sub plots in a single figure to show different aspects of a data, then the subplots() function should be used. Let us understand the code of the live example which is given below in which we have plotted two sub plots. Let us cover a live example to understand this function in more detail. The output for the above code is as follows: With the given below code snippet, we will create a figure having 2 rows and 2 columns of subplots. Let us understand this method with the help of a few examples: Example 1: It can be an Axes object or an array of Axes objects. The values returned by these function are as follows:įig: This method is used to return the figure layout.Īx: This method is mainly used to return the axes. Matplotlib subplots() Function Returned Values You can use a single axis label, centered in the plot frame, to label multiple subplot axes. When using multiple subplots with the same axis units, it is redundant to label each axis individually, and makes the graph overly complex. This parameter is used to indicate the dict with keywords passed to the GridSpec constructor that is used to create the grid on which the subplots are placed on. Using a single axis label to annotate multiple subplot axes. This parameter is used to indicate the dict with keywords that are passed to the add_subplot call which is used to create each subplot. This optional parameter usually contains boolean values with the default is True. To control the sharing of properties among x (sharex) or among y (sharey) axis these parameters are used. The parameter nrows is used to indicate the number of rows and the parameter ncols is used to indicate the number of columns of the subplot grid. Let us discuss the parameters used by this function: The basic syntax to use this function is as follows: (nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw) Matplotlib subplots() Function Parameters Various kind of subplots supported by matplotlib is 2x1 vertical, 2x1 horizontal or a 2x2 grid. Various kind of subplots supported by matplotlib is 2x1 vertical. The main objective of this function is to create a figure with a set of subplots.
This function helps in creating common layouts of subplots and it also includes the enclosing figure object, in a single call. The main objective of this function is to create a figure with a set of subplots. The subplots () function in the Matplotlib acts as a utility wrapper. The subplots() function in the Matplotlib acts as a utility wrapper.
In this tutorial, we will cover the subplots() function in the state-based interface Pyplot in the Matplotlib Library.