A Menagerie of Imports

For newbies to MPL, needed imports seem a bit baffling. scipy, pylab, matplotlib, ...? What libs or lib components do I only need for a particular use? Suppose I want to produce a scatter, contour, or 3d plot. What do I need minimally or more widely? I'm assuming that I don't want to use import matplotlib a lot, but something selectively like from matplotlib.image import AxesImage, or from matplotlib.plot import figure, show. What did I miss in my Python upbringing?

···

--
"Crime is way down. War is declining. And that's far from the good news." -- Steven Pinker (and other sources) Why is this true, but yet the media says otherwise? The media knows very well how to manipulate us (see limbic, emotion, $$). -- WTW

Hi,

For newbies to MPL, needed imports seem a bit baffling. scipy, pylab,
matplotlib, ...? What libs or lib components do I only need for a
particular use? Suppose I want to produce a scatter, contour, or 3d

Like you said: Depends on the particular use. How to give a universal answer?

Matplotlib does very much for you, but you still need to use your head a
little bit. Nobody forces you to "from pylab import *" if a "from pylab
import linspace" was enough. So take a look at you code, that should be
enough. If you are still not satisfied maybe you try to search for "python
unused imports", maybe you find a profiler or something like that that helps
you. In addition, reading the documentation text to the functions (with ?func
or help func in ipython) helps to find out where the modules come from if you
did excessive importing jobs before.

If you just want to work on these in isolation,
you just need
     import matplotlib.pyplot as plt
Nothing more. You can now use e.g. plt.plot
whenever you want.
http://matplotlib.sourceforge.net/users/pyplot_tutorial.html

But if you want to embed Matplotlib in a GUI
(for example, to make a Tkinter application),
you will have to learn some additional details.
GUI is best learned by modifying examples,
and Matplotlib provides *many* examples.

Here are a few extra hints:
http://econpy.googlecode.com/svn/trunk/software4econ.xhtml#mpl_hints

Alan Isaac

···

On 2/11/2010 1:24 PM, Wayne Watson wrote:

Suppose I want to produce a scatter, contour, or 3d
plot. What do I need minimally or more widely?