Forcing the size of a figure
From: Stan West [mailto:stan.west@…595…]
Sent: Monday, August 15, 2011 13:21
From: David Just [mailto:Just.David@…1006…]
Sent: Friday, August 12, 2011 11:05
Now that I’m pre-building all my enlarged interpolated images to scroll through, I’m having trouble forcing the figure/FigureCanvas to be the size I want. I’m trying: fig.set_size_inches(768 / 72.0, 768 / 72.0), but it ends up the same size as the default plot.
If the issue is that the GUI window is not changing size, try adding “forward=True” to the set_size_inches call.
Developers:
As I was checking this with v. 1.0.1, I noticed that the Qt4Agg and TkAgg backends are inconsistent in how they set the size of a figure. Here is the Qt4Agg behavior:
>>> fig = plt.figure(figsize=[6, 4]) >>> print fig.get_size_inches() [ 6. 3.97916667] >>> fig.set_size_inches([6, 4], forward=True) >>> print fig.get_size_inches() [ 6. 3.4375]
The initial figure size isn’t quite right, and the size after set_size_inches is worse. (Is the resize ignoring the toolbar height?) Here is the TkAgg behavior:
>>> fig = plt.figure(figsize=[6, 4]) >>> print fig.get_size_inches() [ 6.125 4.125] >>> fig.set_size_inches([6, 4], forward=True) >>> print fig.get_size_inches() [ 6. 3.64583333]
Again, the initial size is off (due to the window border?), and the resized size is incorrect (toolbar again?).
The WXAgg backend correctly sets the figure canvas to the desired size:
>>> fig = plt.figure(figsize=[6, 4]) >>> print fig.get_size_inches() [ 6. 4.] >>> fig.set_size_inches([6, 4], forward=True) >>> print fig.get_size_inches() [ 6. 4.]
I didn’t check any other backends.
I didn’t see any indication in the master branch that this behavior has changed since 1.0.1. I didn’t find a report for this issue on the tracker; shall I create one?