There is a new method in the figure canvas in CVS that I would like
the maintainers of the various GUI backends to implement
def resize(self, w, h):
set the canvas size in pixels
This should set the canvas (not window) size and trigger a GUI resize
event so that the window is resized accordingly. There is a reference
implementation in backend_gtk.py. You should be able to lift the
logic for computing the new canvas size directly from that code.
Among other things, this will allow better control of the canvas size
from a script or shell. Eg, the following works with GTKAgg in an
In : fig = figure()
In : fig.set_figsize_inches(3,4,forward=True)
In : fig.canvas.resize(500,600)
Ie, you can set the canvas size either in pixels or inches depending
on which method you choose.
Also, I added a new connect signal 'resize_event' that triggers a
backend_bases.ResizeEvent on a canvas.resize. You should call
from the part of your code that handles GUI configure events (see for
example the GTK and GTKAgg backends). Note depending on your toolkit,
you may not want to call this from the FigureCanvas.resize method.
Eg, in GTK* calling "canvas.resize" triggers a call to
canvas.configure_event, which in turn sets the new figure size
properties and once all this is done, calls canvas.resize_event.
Here is some test code
from pylab import figure, connect, show
fig = figure()
print 'resize canvas', event.width, event.height
Checking in lib/matplotlib/backend_bases.py;
/cvsroot/matplotlib/matplotlib/lib/matplotlib/backend_bases.py,v <-- backend_bases.py
new revision: 1.69; previous revision: 1.68