FW: [Matplotlib-users] Forcing the size of a figure

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?

Hi Stan,
this size problem sounds somewhat familiar to me. I had a serious
headache to get the interaction of wx.ScrolledWindow, wx.BoxSizer and
matplotlib.backends.backend_wxagg.FigureCanvasWxAgg right when zooming a
canvas in and out and resizing the window.

I am not sure if it will help you, but I've attached how exactly I set
up the three elements to behave as I wish. Unrelated code is stripped
from the example.

Hope that helps!

Dieter

size_example.py (2.24 KB)

···

Am Montag, den 15.08.2011, 13:30 -0400 schrieb Stan West:

        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?

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at: http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options