How to place a canvas in a scrolledwindow and change its size?

Dear matplotlib users,
I am a new enthusiastic member of the matplotlib community.

I'll start up my frequentation in the ml with two questions for which I
couldn't find an answer; the first one is relatively tricky while the second
one should be quite straigthforward. Both are, I believe, of general

1) I use matplotlib and the wxmpl library to wrap the graphs in a notebook
page of a wxpython application. My canvas is a wxmpl.PlotPanel which is a
derivation of FigureCanvasWxAgg.Everything works just great, I love it.
Thing is that while most graphs have contained size, certain graphs can be
actually composed of several subplots and therefore I would like them to be
plotted on bigger canvas.

I can create a big canvas in a scrolledwindow with big virualsize and this
works just fine.
What I cannot do is to dinamically resize the canvas after it has been
create, ie. Create a smaller canvas and then increase its size only if

One more thing is that if I put the canvas in a sizer and then set the
scrolledwindow to fit the sizer than the canvas changes its dimension
accortding to the dimension of the frame (meaning if I maximize the whole
frame I seem to get a bigger canvas.
Here some graphic examples:

This is what I have now

Class MyNoteBookpage(wx.panel):
  def _init_ ...
    #In the notebook page self, create scrolledwindow
    self.virtualw = wx.ScrolledWindow(self)
    #Create Canvas, child of the scrolledwindow
    self.canvas1 = MyCanvas(self.virtualw)

    #now arrange the sizer
    self.cs = wx.BoxSizer()
    self.cs.Add (self.canvas1, 1, wx.GROW|wx.ALL, 1)

This code will result in this:
Note that in the panel I also have a grid and a textbox and some buttons,
all arranged within a sizer.

If I resize the figure using

  fig.set_size_inches((10,10)) I get this:

2) Is it possible to include in my subplot a custom drawing?
I would like to have a half filled rectangle below the x axis, like the one
you see on panel b of the figure:

Thanks a lot,



I asked some help last week.
I post here the solution to my problem since I believe it's something of
general interest.
A figure is generated and the user can change the size of the canvas (in
inches) interactively, as if we are zooming in and out the canvas.
This is particularly useful when you are drawing figures that can have few
or many subplots.

I couldn't manage to get this working with a resize so the trick is that
every time we destroy and create the canvas.



import wx, wxmpl
from numpy import *

class PanelWScrolledWindow(wx.ScrolledWindow):
  def __init__(self,parent):
    wx.ScrolledWindow.__init__(self, parent)

    self.mainsizer = wx.BoxSizer(wx.VERTICAL)
    self.BTNsizer = wx.BoxSizer(wx.HORIZONTAL)
    self.width, self.heigth = 3, 6

    BTNsmall = wx.Button(self, -1, "Smaller FIG")
    BTNbig = wx.Button(self, -1, "Bigger FIG")

    self.Bind(wx.EVT_BUTTON, self.onBTNbig, BTNbig)
    self.Bind(wx.EVT_BUTTON, self.onBTNsmall, BTNsmall)
    self.BTNsizer.Add (BTNsmall, 0, wx.GROW|wx.ALL, 1)
    self.BTNsizer.Add (BTNbig, 0, wx.GROW|wx.ALL, 1)
    #Note that in a real world you want the button to be outside
the scrolledwindow

    self.mainsizer.Add (self.BTNsizer, 0, wx.GROW|wx.ALL, 1)


  def CreateCanvas(self, size=(2,4)):
    self.canvas = wxmpl.PlotPanel(self, -1, size)
    self.SetScrollbars(20, 20, size[0]/20, size[1]/20)
    self.mainsizer.Add (self.canvas, 1, wx.GROW|wx.ALL, 1)
  def onBTNbig(self,event):
    self.heigth += 1
    self.width +=1

  def onBTNsmall(self,event):
    self.heigth -= 1
    self.width -=1

class MyFrame(wx.Frame):
  def __init__(self, parent, title):
    wx.Frame.__init__(self, parent)

    self.nb = wx.Notebook(self)

    self.PageOne = PanelWScrolledWindow(self.nb)
    self.PageTwo = wx.Panel(self.nb)

    self.nb.AddPage(self.PageOne, "PageOne")
    self.nb.AddPage(self.PageTwo, "PageTwo")

def plot_simple(fig):

  t = arange(0.0, 2.0, 0.01)
  s = sin(2*pi*t)
  c = cos(2*pi*t)
  axes = fig.gca()
  axes.plot(t, s, linewidth=1.0)
  axes.plot(t, c, linewidth=1.0)
  axes.set_xlabel('time (s)')
  axes.set_ylabel('voltage (mV)')
  axes.set_title('About as simple as it gets, folks')

#here we start
app = wx.PySimpleApp()
frm = MyFrame(None, "Test")