In the pyplot documentation I saw
plt.subplt(211) which is identical to subplot(2, 1, 1)
I've also seen 211 being used elsewhere. Why specifically are those numbers being used as opposed to other ones?
The subplot() Function 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. plt.subplot(1, 2, 1) #the figure has 1 row, 2 columns, and this plot is the first plot.
subplot(333) do? Create a blank plot that fills the figure. Create a plot with three points at location (3,3). Create a smaller subplot in the topleft of the figure.
What is the equivalent of subplot (1, 1, 1)? Explanation: While using subplot (1,1,1), we have allocated memory as a 2-D matrix for only 1 graph. This is similar to the axes command which generates an empty graph.
subplot(subplot(nrows, ncols, index) In the current figure, the function creates and returns an Axes object, at position index of a grid of nrows by ncolsaxes. Indexes go from 1 to nrows * ncols, incrementing in row-major order. Ifnrows, ncols and index are all less than 10.
plt.subplot
takes three arguments, the number of rows (nrows
), the number of columns (ncols
) and the plot number. Using the 3-digit code is a convenience function provided for when nrows
, ncols
and plot_number
are all <10
.
So, 211
is equivalent to nrows=2
, ncols=1
, plot_number=1
.
From the docs:
Return a subplot axes positioned by the given grid definition.
Typical call signature:
subplot(nrows, ncols, plot_number)
Where nrows and ncols are used to notionally split the figure into
nrows * ncols
sub-axes, andplot_number
is used to identify the particular subplot that this function is to create within the notional grid.plot_number
starts at 1, increments across rows first and has a maximum ofnrows * ncols
.In the case when
nrows
,ncols
andplot_number
are all less than 10, a convenience exists, such that the a 3 digit number can be given instead, where the hundreds representnrows
, the tens representncols
and the units representplot_number
. For instance:subplot(211)
produces a subaxes in a figure which represents the top plot (i.e. the first) in a 2 row by 1 column notional grid (no grid actually exists, but conceptually this is how the returned subplot has been positioned).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With