简体   繁体   中英

How do I set the matplotlib window size for the MacOSX backend?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM