Thanks to Ken and John, I think I am off and running.  Nice work on
wxmpl Ken!  I think it fills a significant need.

The two attached files show a ridiculously simple example of what I am
planning to do.  It may be completely obvoius to others.
is an example of a module that can be used from the command line with
pylab and IPython and it can also be imported into a WX app (as
demonstrated by  So, I will edit my data processing
scripts to use this approach.

Thanks again,


On 3/19/07, Ryan Krauss <[EMAIL PROTECTED]> wrote:
Sorry, I just googled wxmpl and found your page and am now downloading
it.  I may have a more intelligent question momentarily.  You may
ignore that part of my response.


On 3/19/07, Ryan Krauss <[EMAIL PROTECTED]> wrote:
> Thanks for your thoughts Ken.  Sorry, I assumed a bit on the context
> of my comments.  I have some data processing utility scripts and I
> want to now use with a WX application.  The problem is that the
> utility modules were written without any thought of this future use in
> mind and in all of them I have something like
> from pylab import figure, cla, clf, plot, semiliogx, show, ...
> at the top.  This makes them completely incompatible with embedding in
> a WX application.  So, I need to re-write them and I want to know how
> to do that best.  John had some suggestions and I had some new
> questions as I tried to act on his thoughts.  So, the actual plotting
> functions don't have to be re-useable in both contexts, but it would
> be nice.
> I can't actually run your code because I don't have the
> module.  Looking at it, it looks like a really nice set of functions
> that work cleanly with embedding in a backend.  How could I call one
> of the functions from the command line?  Could I do something like:
> import plotting, pylab
> myfig = pylab.figure()
> plotting.plot_simple(myfig)
> and would I need any additional commands to actually show the figure?
> Let me know if that makes sense and please send me the file
> or let me know where I can get it.
> Thanks again,
> Ryan
> On 3/19/07, Ken McIvor <[EMAIL PROTECTED]> wrote:
> > Ryan,
> >
> > In my (limited) experience, it's dicey to mix pylab's plotting
> > functionality and the OO API.  I guess I'm a little unclear exactly
> > what your use case is for this.  It sounds like you're goal is to
> > create a library of functions that operate on Figure instances,
> > perhaps so you can use them both interactively and as part of a
> > wxPython application.
> >
> > If that's the case, I'd recommend you try using pylab's gcf() and draw
> > () to acquire and redraw the current Figure instance from within
> > IPython.  You can also save the return value of pylab's figure(),
> > which returns a Figure that's already been attached to the
> > appropriate renderer.  This way you can use the OO API for plotting
> > without having to futz with the drawing machinery directly.
> >
> > This script might give you some ideas about how to structure your
> > code.  It contains several of the MPL examples re-coded as functions
> > that accept a Figure instance and use the OO API for plotting.
> >
> >
> >
> > Ken
> >

def myplot(fig, x, y):
    myaxes = fig.gca()

if __name__ == '__main__':
    import pylab
    from scipy import arange, pi, sin
    myfig = pylab.figure()
import wxmpl

# Create the PlotApp instance.
# The title string is one of several optional arguments.
app = wxmpl.PlotApp('WxMpl Example 1')

from matplotlib.numerix import arange, pi, sin
x = arange(0.0, 1, 0.01)
y = sin(2*pi*x)

### Plot it ###

# All of WxMpl's plotting classes have a get_figure(),
# which returns the associated matplotlib Figure.
fig = app.get_figure()

import test_plot

test_plot.myplot(fig, x, y)

# <== This spot is where the plotting happens

# Let wxPython do its thing.

Take Surveys. Earn Cash. Influence the Future of IT
Join's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
Matplotlib-users mailing list

Reply via email to