Resizing figure windows?

Hello,
I'm trying to resize a matplotlib figure window as part of an
interactive IPython session. I occasionally draw plots that have
strong opinions about the size or aspect ratio of the plotting window,
and I'd like to be able to just put those preferences into the
function that draws the plot.

I can do this:

In [96]: gcf().set_size_inches(15,15); draw()

But then I'm in the awkward position that the canvas doesn't fit
inside the window and only a small part of the plot is visible. If I
touch the corner of the window with the mouse, then the canvas
immediately resizes to the size of the window, destroying my desired
size or aspect ratio.

After a little googling and digging around in the matplotlib objects,
I was able to do this:
gcf().canvas._tkcanvas.master.geometry("800x800")

which does successfully resize the plotting window, but violates all
pretense of hiding the details of the backends from the plotting code.
I had hoped that once I figured out how to do this the ugly way then
grepping the matplotlib source tree for "geometry" would lead me to
the "right" way to do this. Alas, that strategy didn't work.

I'm using version 0.99.1.1 with the TkAgg backend.

Thanks,
Greg

set_size_inches method takes a "forward" parameter, which adjusts the
window size if True, which I believe is what you want. However,
according to the documentation, this is only supported in the Gtk and
Wx backend.
So, easy way would be to switch to other backend if possible.

I quickly go through the source and attached is a patch that seems to
fix this for the Tk backend. I never use Tk and I just put the
relevant command (copied from your email) at what I think is the right
place (but this may introduce some problem although my quick test
worked). So, please give it a try.

Unless some other developers (who knows Tk) does not pick this up,
I'll commit it after a few days of testing.

Regards,

-JJ

tk_resize.patch (829 Bytes)

ยทยทยท

On Mon, Dec 21, 2009 at 4:55 PM, Greg Novak <novak@...354...> wrote:

Hello,
I'm trying to resize a matplotlib figure window as part of an
interactive IPython session. I occasionally draw plots that have
strong opinions about the size or aspect ratio of the plotting window,
and I'd like to be able to just put those preferences into the
function that draws the plot.

I can do this:

In [96]: gcf().set_size_inches(15,15); draw()

But then I'm in the awkward position that the canvas doesn't fit
inside the window and only a small part of the plot is visible. If I
touch the corner of the window with the mouse, then the canvas
immediately resizes to the size of the window, destroying my desired
size or aspect ratio.

After a little googling and digging around in the matplotlib objects,
I was able to do this:
gcf().canvas._tkcanvas.master.geometry("800x800")

which does successfully resize the plotting window, but violates all
pretense of hiding the details of the backends from the plotting code.
I had hoped that once I figured out how to do this the ugly way then
grepping the matplotlib source tree for "geometry" would lead me to
the "right" way to do this. Alas, that strategy didn't work.

I'm using version 0.99.1.1 with the TkAgg backend.

Thanks,
Greg

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options