I have a python plotting function that creates a grid of matplotlib subplots and I want the size of the window the plots are drawn in to depend on the size of the subplot grid. For example, if the subplots grid is 5 rows by 5 columns (25 subplots) the window size needs to be bigger than one where there is only 5 subplots in a single column. I'm not sure how to control the window size matplotlib creates plots in. Can someone tell me how to control the plot window size for matplotlib using the MacOSX backend?
1 Answer. Show activity on this post. In general, for any matplotlib figure object, you can also call fig. set_size_inches((width, height)) to change the size of the figure.
If not provided, defaults to rcParams["figure. figsize"] (default: [6.4, 4.8]) = [6.4, 4.8] .
For all backends, the window size is controlled by the figsize
argument.
For example:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(5, 5, figsize=(12, 10))
plt.show()
If you're creating the figure and subplots separately, you can specify the size to plt.figure
(This is exactly equivalent to the snippet above):
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(12, 10))
for i in range(1, 26):
fig.add_subplot(5, 5, i)
plt.show()
In general, for any matplotlib figure object, you can also call fig.set_size_inches((width, height))
to change the size of the figure.
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