Matplotlib-users digest, Vol 1 #632 - 14 msgs

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)

Alternatively, how would it look if I wanted to add the plot to a
wx.window? This might be a more simple case... either way I'm not sure
how to do this? I appreciate the help! Thanks.

Jeff

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()

···

#####################

Hi Jeff,

As you are using Boa this might be helpful to you (Matt, no I can't read minds but Jeff posted another problem to the Boa list).

I use a splitter to have on the left side some selection criteria and on the right side the figure or multiple figures.

You can not directly use matplotlib in the Boa Frame designer, but you can do the following.

Anywhere after:
     def __init__(self, parent):
         self._init_ctrls(parent)

I do this:
         self.figure = Figure()
         self.canvas = FigureCanvas(self.splitter, -1, self.figure)

         old = self.splitter.GetWindow2()
         if old == None:
             self.splitter.SplitVertically(self.selectionPanel, self.canvas, 350)
         else:
             self.splitter.ReplaceWindow(old, self.canvas)

Hope this helps
Werner

Jeff Peery wrote:

···

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)

Alternatively, how would it look if I wanted to add the plot to a
wx.window? This might be a more simple case... either way I'm not sure
how to do this? I appreciate the help! Thanks.

Jeff

-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20

Perfect! Thanks!

Jeff

···

-----Original Message-----
From: Matt Newville [mailto:newville@…189…]
Sent: Friday, June 03, 2005 11:47 AM
To: Jeff Peery
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] RE: Matplotlib-users digest, Vol 1 #632
- 14 msgs

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()
#####################