From: James Casbon <casbon@gm...> - 2005-11-24 15:23:22
The logic for displaying a figure on the interactive backends (eg qt)
seems a little strange to me. I imagine that normally the screen is
used as a preview for a figure that is going to be output on paper, or
to png or some permanent store. Therefore, the interactive output
should resemble the permanent output as much as possible.
Now, when using the QtAgg backend (sorry no time to play with other
backends) setting the figure height or width has no effect on the size
of the figure displayed with show(). It always comes out at 600x400.
Further, given that the window can be resized or embedded, ideally
what is displayed should be as good a representation of the figure as
possible. It is not, however. To see this try resizing the window -
fonts sizes, linewidths, etc. stay the same size.
I can make the rendering more realistic using the dpi setting. This
can be achieved using this implementation of resizeEvent (from
backend_qt_agg.py / FigureCanvasQtAgg). The original code is
def resizeEvent( self, e ):
FigureCanvasQT.resizeEvent( self, e )
w =3D e.size().width()
h =3D e.size().height()
if DEBUG: print "FigureCanvasQtAgg.resizeEvent(", w, ",", h, ")"
#dpival =3D self.figure.dpi.get()
#winch =3D w/dpival
#hinch =3D h/dpival
#self.figure.set_figsize_inches( winch, hinch )
if w/self.figure.get_figwidth() < h/self.figure.get_figheight():
self.figure.set_dpi( w/self.figure.get_figwidth() )
self.figure.set_dpi( h/self.figure.get_figheight() )
The original implementation doesn't really do anything to how the
figure is displayed. The new one makes the plot appear how it should
no matter what the window's size.
This is not ideal, however, as if the figure is saved now the dpi will
be wrong. So there are two questions really: is this a better way
for the interactive windows to display? If so, where should this
From: John Hunter <jdhunter@ac...> - 2005-11-30 21:50:13
>>>>> "James" == James Casbon <casbon@...> writes:
James> Hi, The logic for displaying a figure on the interactive
James> backends (eg qt) seems a little strange to me. I imagine
James> that normally the screen is used as a preview for a figure
James> that is going to be output on paper, or to png or some
James> permanent store. Therefore, the interactive output should
James> resemble the permanent output as much as possible.
James> Now, when using the QtAgg backend (sorry no time to play
James> with other backends) setting the figure height or width has
James> no effect on the size of the figure displayed with show().
James> It always comes out at 600x400.
Typically you want saved images to be at a higher resolution than the
one on the screen, since most screens are less than 1500x1500 and
often you want a higher resolution setting. That is why the savefig
command takes a dpi parameter, which default to the settin in your rc
file. You could make the screen dpi and the savefig dpi the same in
rc if you want.
I find that when I resize a figure in the GUI window, the aspect ratio
*is* preserved when I save, so the suggestion above should suffice for