Wanted: recommendations on embedding matplotlib in a wxPython application

The wiki suggests either MPlot or WxMpl for embedding. Which might be
preferable for a display-only use? In other words, what would be the simpliest, easiest, most pragmatic approach?

So far in my experience, and as I was recommended, the “simpliest, easiest,
most pragmatic approach” has been to forgo MPlot or WxMpl and just embed
directly in wxPython.
This page discusses the difference between direct embedding and using
an embedding library, the key difference for you being this sentence:
“An embedding library saves you a lot of time and effort by
providing
plotting widgets that already support user interactions and
other bells and
whistles.” But you don’t want such bells and whistles. There is a link on
that page to this example of direct embedding with wx. I was able to start

with this and adapt it to my needs.

So far in my experience, and as I was recommended, the "simplest,
easiest, most pragmatic approach" has been to forgo MPlot or WxMpl and
just embed directly in wxPython.

   That is the insight I seek. I've looked at the examples and the cookbook
page ...

This page <http://www.scipy.org/Cookbook/Matplotlib/EmbeddingInWx&gt;
discusses the difference between direct embedding and using an embedding
library, the key difference for you being this sentence: "An *embedding
library* saves you a lot of time and effort by providing plotting widgets
that already support user interactions and other bells and whistles." But
you don't want such bells and whistles.

   No, I don't need bells or whistles.

There is a link on that page to this
example<http://www.scipy.org/Matplotlib_figure_in_a_wx_panel&gt;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.

   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?

Rich

···

On Mon, 26 Nov 2007, C M wrote:

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

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

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

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:

   This is all straightforward and clear. The one statement I've not yet
understood is this:

       self.graph = matplotFrame3.PlotPanel(self.panel1,xpoints, ypoints)

   I assume that matplotFrame3 is the name of the module in which you've
written PlotPanel(). Is this assumption correct?

   I'm modifying your approach to suit our application but it seems to be the
most parsimonious and elegant solution for simple display of plots in a
wxPython panel.

Thanks,

Rich

···

On Mon, 26 Nov 2007, C M wrote:

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

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:

This is all straightforward and clear. The one statement I’ve not yet
understood is this:

   self.graph = matplotFrame3.PlotPanel(self.panel1

,xpoints, ypoints)

I assume that matplotFrame3 is the name of the module in which you’ve
written PlotPanel(). Is this assumption correct?

Exactly. That is the module which I mention importing in step 4.

I’m modifying your approach to suit our application but it seems to be the

most parsimonious and elegant solution for simple display of plots in a
wxPython panel.

Thanks,

Glad it will help your application.

···

On Nov 27, 2007 11:27 AM, Rich Shepard <rshepard@…695…> wrote:

On Mon, 26 Nov 2007, C M wrote:

I may be jumping into this conversation way too late, but I really
like wxmpl. The one bell and whistle that I love is the
click-and-drag box zoom available by default. Attached is my hacked
together simple example of putting a wxmpl.PlotPanel on a wx.notebook.

Ryan

simple_wxmpl_embedded.py (2.71 KB)

···

On Nov 27, 2007 11:06 AM, C M <cmpython@...287...> wrote:

On Nov 27, 2007 11:27 AM, Rich Shepard <rshepard@...695...> wrote:
>
> On Mon, 26 Nov 2007, C M wrote:
>
>
> > 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:
>
> This is all straightforward and clear. The one statement I've not yet
> understood is this:
>
>
> > self.graph = matplotFrame3.PlotPanel(self.panel1 ,xpoints,
ypoints)
>
> I assume that matplotFrame3 is the name of the module in which you've
> written PlotPanel(). Is this assumption correct?
>

Exactly. That is the module which I mention importing in step 4.

>
> I'm modifying your approach to suit our application but it seems to be
the
> most parsimonious and elegant solution for simple display of plots in a
> wxPython panel.
>
> Thanks,
>
>
>
>
Glad it will help your application.

-------------------------------------------------------------------------
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
matplotlib-users List Signup and Options

Ryan,

   Thank you very much. Our application neither needs nor wants user
interaction. The plots are strictly for display.

Rich

···

On Wed, 28 Nov 2007, Ryan Krauss wrote:

I may be jumping into this conversation way too late, but I really like
wxmpl. The one bell and whistle that I love is the click-and-drag box
zoom available by default. Attached is my hacked together simple example
of putting a wxmpl.PlotPanel on a wx.notebook.

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863