Jeff,
Hello, I'm using wx.Agg as a backend for wxpython. I would like to put
a plot inside a splitter window. Something that looks like this:
#adjust figure size
self.figure = Figure(figsize=(0.5,1), dpi=100)
#create the canvas
self.canvas = FigureCanvas(self, -1, self.figure)
#add canvas to splitter window
self.splitterWindow2.SplitVertically(self.window1,self.canvas,4)
#create a plot instance
self.axes = self.figure.add_subplot(111)
It's definitely no problem to put a FigureCanvasWxAgg on a
wx.Window or wx.Panel as in:
class Plotter(wx.Window):
def __init__(self,parent=None):
wx.Window.__init__(self,parent,-1)
self.fig = Figure((5,4), 75)
self.canvas = FigureCanvasWxAgg(self,-1,self.fig)
self.axes = self.fig.add_axes([0.12,0.12,0.76,0.76])
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas,1, wx.LEFT|wx.TOP)
self.SetSizer(sizer)
self.Fit()
def plot(self,x,y,*args,**kwds):
"very simple plot !!"
self.axes.cla()
self.axes.plot(x,y,*args,**kwds)
(and wx.Window can be replaced by wx.Panel). A more complete
example is below, though not with a splitter window, it shows
that the Plotter can be placed anywhere. Hope that helps,
--Matt
#!/usr/bin/env python
import wx
import matplotlib.numerix as nx
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
class Plotter(wx.Window):
def __init__(self,parent=None):
wx.Window.__init__(self,parent,-1)
self.fig = Figure((5,4), 75)
self.canvas = FigureCanvasWxAgg(self,-1,self.fig)
self.axes = self.fig.add_axes([0.12,0.12,0.76,0.76])
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas,1, wx.LEFT|wx.TOP)
self.SetSizer(sizer)
self.Fit()
def plot(self,x,y,*args,**kwds):
"very simple plot !!"
self.axes.cla()
self.axes.plot(x,y,*args,**kwds)
class PlotFrame(wx.Frame):
def __init__(self,parent=None):
wx.Frame.__init__(self,parent,-1,'Frame')
self.plotwin = Plotter(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(wx.StaticText(self, -1 , ' WX Matplotlib example ')
,0, wx.LEFT|wx.TOP)
sizer.Add(self.plotwin,1, wx.LEFT|wx.TOP)
self.SetSizer(sizer)
self.Fit()
def plot(self,x,y,*args,**kwds):
self.plotwin.plot(x,y,*args,**kwds)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = PlotFrame()
x = nx.arange(0,10.0,0.05)
y = nx.sin(x*nx.pi/3)
frame.plot(x,y,'ro')
frame.Show()
app.MainLoop()
···
#####################