[Numpy-discussion] Numeric3

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Feb 8 18:46:10 CST 2005


>>>>> "Ralf" == Ralf Juengling <juenglin at cs.pdx.edu> writes:

    >> Ha! That's the core problem here. As an example (I don't mean
    >> to be picking on you, John) matplotlib docs suggest that you do
    >> things differently when writing programs than playing with the
    >> interpreter.  However, almost all of the examples and docs, and
    >> and most of the usability effort has gone into the "import *"
    >> approach. The same is true for Numeric and numarray. Why would
    >> someone magically stop using it?  Besides, I use the
    >> interactive interpreter to try out code that I'm then going to
    >> use in a program. Why have a different syntax?

    Ralf> Yes, I think it is absurd to ask a user to learn two APIs,
    Ralf> one for interactive use and one for writing programs.

Just to make sure I'm not being unfairly represented here :-)

matplotlib has a pylab interface which allows you to make plots from
scripts or from the python shell.  Eg you can do
 
  from pylab import *
  plot([1,2,3])
  xlabel('hi mom')

and a figure window will pop up if you've configured your matplotlib
environment for interactive use with a GUI.  Now a lot happens under
the hood when you make these commands -- in particular, the pylab
interface has the concept of the current figure and axes, and these
are created automagically for you if you haven't explicitly created
them already.  Which means the module is realizing and managing GUI
windows, binding events to them, managing their destruction, and so
on.

What we advise is if you are using matplotlib in a GUI application you
are writing -- eg you are explicitly creating wx/gtk/tk/etc windows
and toolbars and menus -- then you shouldn't use the pylab interface.
The reason is that the pylab interface is trying to create and manage
GUI windows, and you might get into a conflict if you are also trying
to create and manage GUI windows.  So as a GUI application developer,
you are responsible for these things and use the matplotlib OO API --
the pylab interface is a thin wrapper to this.

I think the misleading statement is

    >> you do things differently when writing programs than playing
    >> with the interpreter

it would be accurate to say you should not use the pylab interface
when manually embedding matplotlib in a GUI, but you are free to use
the pylab interface or the OO API in python scripts or from the python
shell.

And now we have wandered dangerously off-topic...

JDH




More information about the Numpy-discussion mailing list