[SciPy-user] Chaco & wxWindows

Peter Wang pwang at enthought.com
Mon Nov 28 17:50:09 CST 2005


basvandijk at home.nl wrote:
> My application has a: "class PlotPanel(wxPanel)" in which I call: 
> "self.plt = scipy.plt.wxplt.plot_window(self, -1)" to create a plotting window and "self.plt.plot(...)" to plot my data.
> 
> What is the best way to convert my application to Chaco?

Hi Bas,

It is relatively easy to embed a Chaco plot into a WX panel:

-----------------------
import wx
from Numeric import arange, sin
from enthought.enable.wx import Window
from enthought.chaco.wx.plot import PlotComponent, PlotCanvas, PlotValue

class MyFrame ( wx.Frame ):
     def __init__ ( self, *args, **kw ):
         wx.Frame.__init__( *(self,) + args, **kw )
         data = sin(arange(-5.0, 5.0, 0.3))
         plot = PlotValue(data, type="scatter,line")
         plot_window = Window(self, component=PlotComponent(plot))

         sizer = wx.BoxSizer(wx.HORIZONTAL)
         sizer.Add(plot_window.control, 1, wx.EXPAND)
         self.SetSizer(sizer)
         self.SetAutoLayout( True )
         self.Show( True )

-----------------------

Note that this is using the latest stuff from the enthought lib, and not the 
old version of Chaco that was bundled with Enthon.  If you don't have it, you 
will need to grab it and do a quick build per the instructions here:
http://www.enthought.com/enthought/wiki/GrabbingAndBuilding

You can add a title, legend, etc. by create PlotLabels and PlotTitles, and 
adding them to a PlotCanvas.  You can look in chaco/demo/ for demos and code 
samples.

Is there anything you want the user to be able to change about the plot, once 
it's displayed?


-Peter



More information about the SciPy-user mailing list