Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing matplotlib figure with set_fig(width/height) doesn't work

For some reason this code creates a figure that is only the standard size: it doesn't change the height or width (I chose widths and heights that are ludicrous to clearly illustrate the problem):

import matplotlib.pyplot as plt

fig = plt.figure()
fig.set_figwidth(30)
fig.set_figheight(1)

print('Width: {}'.format(fig.get_figwidth()))

plt.show()

I'm running on OSX 10.10.4, Python 3.4.3, Matplotlib 1.4.3. (Installed via Macports.) Any ideas? What am I missing?

like image 625
Joel Avatar asked Aug 05 '15 19:08

Joel


People also ask

How do I increase the size of a figure in Matplotlib?

Import matplotlib. To change the figure size, use figsize argument and set the width and the height of the plot. Next, we define the data coordinates. To plot a bar chart, use the bar() function. To display the chart, use the show() function.

What is the default width and height of a Matplotlib figure?

figsize() takes two parameters- width and height (in inches). By default the values for width and height are 6.4 and 4.8 respectively.


1 Answers

The optional parameter forward propagates changes to the canvas in a GUI window that already exists.

Documentation here:

optional kwarg forward=True will cause the canvas size to be automatically updated; e.g., you can resize the figure window from the shell

Using Figure(figsize=(w,h)) also works.

For Matplotlib 2.2.0 and newer

forward=True is the default for all three of set_figheight, set_figwidth, and set_size_inches (set_size_inches changes both height and width simultaneously).

For Matplotlib 1.5.0

forward=True must be specified explicitly as it is False by default. (In Matplotlib 2.0.0, the default is changed to True only for set_size_inches).

For Matplotlib 1.4.3 and older

forward is only supported by set_size_inches.

set_figheight and set_figwidth do not support this argument, so it is a bit difficult to only change a single dimension of a pre-created GUI.

like image 119
River Avatar answered Nov 15 '22 07:11

River