numpification and imports

I just removed the last vestiges of the numerix extension code layer.
The conditional imports are gone from the extension code, the -D flags
are gone from the compile, as is the _ns_ module naming scheme. This
is a fairly major change, so please blow away your install and build
dirs after updating to r3513

I also numpified axes.py, by far the biggest and most complicated
module, and fixed all of the imports as we discussed in an earlier
thread. One problem I ran into. With the proposed

from matplotlib import lines # and friends

there is a lot of possibility for name clashes. Eg, in some places we
also have a variable names "lines", which isn't life threatening but
certainly can lead to confusion and bugs. Or for module legend, we
also have an Axes function.legend. I decided to go with a foolish
consistency that was unambiguous:

from matplotlib import artist as mpl_artist
from matplotlib import agg as mpl_agg
from matplotlib import axis as mpl_axis
from matplotlib import cbook as mpl_cbook
from matplotlib import collections as mpl_collections
from matplotlib import colors as mpl_colors
from matplotlib import contour as mpl_contour

and then

mpl_cbook.iterable # and so on

Because the mpl_ prefix occurs nowhere else, we can easily change this
to whatever we want with a single search replace.

I also added a module mpl which simply imports all the modules, so API
or pylab users can

  >>> from pylab import mpl

or

>>> from matplotlib import mpl

and have all of the API in one place (mpl.dates, mpl.figure,
mpl.ticker, etc...) -- nice with tab completion an online help in
ipython when you aren't sure where to find something....

I was hoping we could use this in the matplotlib code itself. Eg if
axes could import mpl, then we could replace the somewhat ugly
mpl_cbook with the nice and pretty mpl.cbook, but there is the problem
of recursive imports. Is there a way to do this with some python
magic, so that one "mpl" API module could serve all of the modules?
Something in the back of my mind is telling me there is something in
EGGS with an api module..... Any ideas?

JDH

John Hunter wrote:

from matplotlib import artist as mpl_artist
from matplotlib import agg as mpl_agg
from matplotlib import axis as mpl_axis
from matplotlib import cbook as mpl_cbook
from matplotlib import collections as mpl_collections
from matplotlib import colors as mpl_colors
from matplotlib import contour as mpl_contour

might as well

import matplotlib as mpl

and use mpl.artist, etc.

I don't think this will work in this form. artist is a module, and it
is not imported simply by importing matplotlib

In [1]: import matplotlib as mpl

In [2]: mpl.artist

···

On 7/13/07, Tom Holroyd (NIH/NIMH) [E] <tomh@...234...> wrote:

import matplotlib as mpl

and use mpl.artist, etc.

------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in ?
AttributeError: 'module' object has no attribute 'artist'

John Hunter wrote:

I don't think this will work in this form. artist is a module, and it
is not imported simply by importing matplotlib

In [1]: import matplotlib as mpl

In [2]: mpl.artist

however, this seems to work (though it looks perhaps a bit odd)

import matplotlib as mpl
import matplotlib.artist
mpl.artist

<module 'matplotlib.artist' from
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/artist.pyc'>

I do like this better -- names like mpl_*** rub me the wrong way. it
looks like you really want a namespace -- and indeed you do!

maybe the real solution is to have the matplotlib called "mpl" from the
get go, like wxPython does:

import wx
wx.Whatever...

I do wish that:

import matplotlib as mpl
import mpl.artist

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named mpl.artist

worked.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...

Christopher Barker wrote:

John Hunter wrote:

[...]

I do wish that:

import matplotlib as mpl
import mpl.artist

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named mpl.artist

worked.

The way I have it working now (on my machine, not in svn), when you

import matplotlib as mpl

You don't need to then import mpl.artist; it is already imported, ready for use.

Eric

···

-Chris