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?
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.
figsize() takes two parameters- width and height (in inches). By default the values for width and height are 6.4 and 4.8 respectively.
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.
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.
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