There is a new method in the figure canvas in CVS that I would like
the maintainers of the various GUI backends to implement
class FigureCanvasYourBackend
def resize(self, w, h):
"""
set the canvas size in pixels
"""
pass
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
interactive session:
In [1]: fig = figure()
In [2]: fig.set_figsize_inches(3,4,forward=True)
In [3]: 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
self.resize_event()
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()
def resize(event):
print 'resize canvas', event.width, event.height
connect('resize_event', resize)
show()
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
Thanks!
JDH