> > There is a link on that page to this
> > example<http://www.scipy.org/Matplotlib_figure_in_a_wx_panel>of direct
> > embedding with wx. I was able to start with this and adapt it to my
> needs.
>
> I've looked closely at this, and need to figure out how to translate it
> from a stand-alone example to working in my application.
>
Basically what I did (sorry if this is too basic, but I'm pretty new to this
and this may jog others to correct deficiencies in this simple approach) was
to:
1. Save the two graphing classes from that example (NoRepaintCanvas and
PlotPanel) in their own module for conceptual simplicity and use by various
apps I might make.
2. change the draw() method in PlotPanel to a simpler:
def draw(self):
if not hasattr(self, 'subplot'):
self.subplot = self.figure.add_subplot(111)
self.subplot.plot(self.xpoints, self.ypoints, marker='o', ms=8,
fc='white', mec='blue', mew=1)
this isn't great because you cannot change plot characteristics from the GUI
yet,
but it gets things started (and you may not care).
3. Now the class PlotPanel needs a place to get fed those xpoints and
ypoints, so I
added it in the __init__, along with a call to draw().
def __init__(self,parent, xpoints=[],ypoints=[] ,id = -1, color = None,\
dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):
wx.Panel.__init__(self, parent, id = id, style = style, **kwargs)
self.figure = Figure(None, dpi)
self.xpoints = xpoints
self.ypoints = ypoints
self.canvas = NoRepaintCanvas(self, -1, self.figure)
self.SetColor(color)
self.Bind(wx.EVT_IDLE, self._onIdle)
self.Bind(wx.EVT_SIZE, self._onSize)
self._resizeflag = True
self._SetSize()
self.draw()
4. The classes in the module are set. Then in my main app, I made sure to
at the top of the app import matplotFrame3 and then just reference this
class from there in this method called
add_graph...
def add_graph(self):
if self.graphstate == 1:
self.graph.Destroy()
ypoints = (10,20,20,33,73) #you'll take this from a list somewhere
in your app
xpoints = (1,2,3,4,5) #you'll take this from a list
somewhere in your app
self.graph = matplotFrame3.PlotPanel(self.panel1,xpoints, ypoints)
self.boxSizer1.Insert(4, self.graph, 2, border=5, flag=wx.LEFT |
wx.TOP |wx.EXPAND)
self.boxSizer1.Layout()
self.graphstate = 1
This bit about destroying based on the graphstate (exists or doesn't) was
just a quick way to prevent adding multiple graphs to the sizer, but I'll
clean that up with a better approach later.
Hope this gets you further along.
>
> There's also a reference on that SciPy cookbook page to links to the OO
> API on the matplotlib FAQ page, but I've not found that link(s). I have
> the
> api.pdf but is that the OO one?
>
That I don't know.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users