I am learning the hard way that I don't know as much about matplotlib
as I thought I did except for how to use pylab.

I think I have managed to create a figure, add an axis, and plot
something on it without pylab, but I don't know how to do the
equivalent of show().  draw() needs a renderder and I can't seem to
figure out how to create one.  Here is what I have done so far:

myfig = pylab.Figure()
myaxes=myfig.add_axes((0,1,0,1))
t=arange(0,1,0.01)
y=sin(2*pi*t)
myaxes.plot(t,y)

What do I need to do to show the plot from the command line in IPython
(i.e. if I actually want to use pylab instead of OO)?

I may be going about this the wrong way and it may be easier just to
set up some imports of pylab that only trigger inside of functions,
but I would like to have functions that are useful either from the
IPython command line or in OOP situations.   Following the examples
for WX, I am doing this at the top of my OOP modules:

from matplotlib.backends.backend_wxagg import Toolbar, FigureCanvasWxAgg
from matplotlib.figure import Figure
.
.
.
        
class mplpanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        self.fig = Figure((5,5), 75)
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)


And the my drawing commands operate on self.fig and then the last line
of all plotting functions is self.canvas.draw().

So, it would be nice if my utility functions took a figure instance as
an input and operated on it.

Am I making any sense?  Am I going about this revision in a good way?

Thanks,

Ryan

On 3/15/07, Ryan Krauss <[EMAIL PROTECTED]> wrote:
> Thanks John.  I know I have some clean up to do, I just want to do it
> right so it isn't an annual (or more often) thing....
>
> On 3/15/07, John Hunter <[EMAIL PROTECTED]> wrote:
> > On 3/15/07, Ryan Krauss <[EMAIL PROTECTED]> wrote:
> >
> > > How should I be using matplotlib/pylab in my utility scripts so that
> > > they are compatible with embedding in wx?
> >
> > A good rule of thumb is to never import pylab at the top level for
> > modules that need to be imported.  In my own code, I often do
> > something like
> >
> >   def somefunc(figfunc):
> >       fig = figfunc()
> >       ax = fig.add_subplot(111)
> >       ax.plot([1,2,3])
> >
> > and then I can call it with
> >
> >   somefunc(pylab.figure)
> >
> > or a custom func that generates a GUI embedded figure instance.  Eg,
> > in my GTKApps, I have a functor like gtk_figure that returns a
> > function that creates a figure embedded in a GTK window.
> >
> > In basemap, Jeffrey Whitaker does something like the following
> >
> >   def somefunc(ax=None):
> >       if ax is None:
> >           import pylab
> >           ax = pylab.gca()
> >
> > Here the pylab import is triggered only when the function is called
> > with default arguments.  That way you can use it from GUI code without
> > triggering a pylab import like
> >
> >   somefunc(ax)
> >
> > and from other code where you want pylab do do everything with
> >
> >   somefunc()
> >
> > I'm afraid you have some cleanup to do.....  Mixing pylab with
> > embedded GUI code is a recipe for pain and misery.
> >
> > JDH
> >
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to