Reputation: 2175
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?
Upvotes: 6
Views: 14030
Reputation: 9093
The optional parameter forward
propagates changes to the canvas in a GUI window that already exists.
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.
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).
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
).
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.
Upvotes: 7
Reputation: 2175
I'm not certain why those documented functions don't work, but they have been fixed for the next matplotlib release (>v1.4.3). As a workaround until the next release, replacing set_figwidth
and set_figheight
solves this problem.
import matplotlib.pyplot as plt
fig = plt.figure()
# Instead of set_figwidth(30)
fig.set_size_inches(30, fig.get_figheight(), forward=True)
plt.show()
Upvotes: 4