Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 848
jkueng Avatar asked Feb 18 '15 02:02

jkueng


People also ask

How do I change the size of a window in matplotlib?

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.

What is the default matplotlib figure size?

If not provided, defaults to rcParams["figure. figsize"] (default: [6.4, 4.8]) = [6.4, 4.8] .


1 Answers

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.

like image 116
Joe Kington Avatar answered Oct 07 '22 01:10

Joe Kington