r/matplotlib • u/largelcd • Feb 09 '20
Why subplot(1,1,1)
Hi, I know that by using subplot, we can create a figure with several subplots. Supposing that we have (2,3,1), it tells that in the figure, there are 6 subplots in the form of 2x3 (2 rows, 3 columns of subplots). The last element indicates which subplot is of interest. In this case, it is the one on the top left of the figure.
If there is only one plot in the figure, why somebody uses something like:
import matplotlib.pyplot as plt
fig = plt.figure(); ax = fig.add_subplot(1,1,1)
2
Upvotes
View all comments
Show parent comment
2
u/[deleted] Mar 04 '20 edited Mar 04 '20
Yes. Also, at the risk of dumping to much information here, I find myself using
GridSpeca lot (for complex plots). It works similar toplt.subplotsbut for one extra import line you get the ability to make irregular grids of plots, by doing for example:You can see that this uses the standard python (numpy) slice notation, so the bottom plot spans all of the second row. The demo is here and a more advanced tutorial is available. Anyway, that's a bit more complex that just one plot ;)
edit: fixed example