more on cleanup pylab namespace

Hi,
long time ago there was a discussion on reducing the duplications of
functions / symbols between Numpy and Matplotlib.
I think from this resulted the pylab module now having many fewer entries:

import matplotlib
matplotlib.__version__

'0.98.5.2'

import pylab
len(pylab.__dict__)

882

However, I think these are still to many ! I wrote, already before
the cleanup, a "HACK"-cleanup routine, which makes a cut-down modules
(called P) like this:
# P = new.module("pylab_sparse","""pylab module minus stuff alreay in numpy""")
for k,v in pylab.__dict__.iteritems():
    try:
       if k[:2] == '__' or v is numpy.__dict__[k]:
           continue
    except KeyError:
       pass
    #P.__dict__[k] = v
    exec("%s = pylab.%s" % (k,k))

((the commented out lines did not work, but they might still
illustrate what I want to do -- now I have this code in a separate
module that I can import as "P"

This way I get:

len(P.__dict__)

395

numpy.__version__

'1.3.0'

So why are there still that many -- more than half ! -- duplications
between pylab and numpy ?

Regards,

Sebastian Haase

Hi Sebastian,

You are right. A large number of numpy functions is part of pylab, but I think
this problem was solved by introducing matplotlib.pyplot, which holds all
plotting functions of matplotlib. The module pylab imports these plotting
functions and all the numpy-stuff in order to offer plotting + numerical
functions by one import.

kind regards Matthias

···

On Friday 12 June 2009 10:49:52 Sebastian Haase wrote:

Hi,
long time ago there was a discussion on reducing the duplications of
functions / symbols between Numpy and Matplotlib.

I think from this resulted the pylab module now having many fewer entries:
>>> import matplotlib
>>> matplotlib.__version__

'0.98.5.2'

>>> import pylab
>>> len(pylab.__dict__)

882

However, I think these are still to many ! I wrote, already before
the cleanup, a "HACK"-cleanup routine, which makes a cut-down modules
(called P) like this:
# P = new.module("pylab_sparse","""pylab module minus stuff alreay in
numpy""") for k,v in pylab.__dict__.iteritems():
    try:
       if k[:2] == '__' or v is numpy.__dict__[k]:
           continue
    except KeyError:
       pass
    #P.__dict__[k] = v
    exec("%s = pylab.%s" % (k,k))

((the commented out lines did not work, but they might still
illustrate what I want to do -- now I have this code in a separate
module that I can import as "P"

This way I get:
>>> len(P.__dict__)

395

>>> numpy.__version__

'1.3.0'

So why are there still that many -- more than half ! -- duplications
between pylab and numpy ?

Regards,

Sebastian Haase

See also http://matplotlib.sourceforge.net/faq/usage_faq.html#matplotlib-pylab-and-pyplot-how-are-they-related

JDH

···

On Fri, Jun 12, 2009 at 4:21 AM, Matthias Michler<MatthiasMichler@...361...> wrote:

You are right. A large number of numpy functions is part of pylab, but I think
this problem was solved by introducing matplotlib.pyplot, which holds all
plotting functions of matplotlib. The module pylab imports these plotting
functions and all the numpy-stuff in order to offer plotting + numerical
functions by one import.

Hi Sebastian,

You are right. A large number of numpy functions is part of pylab, but I think
this problem was solved by introducing matplotlib.pyplot, which holds all
plotting functions of matplotlib. The module pylab imports these plotting
functions and all the numpy-stuff in order to offer plotting + numerical
functions by one import.

kind regards Matthias

Matthias,
thanks for the info. thats the info I was missing.

from matplotlib import pyplot
len(pyplot.__dict__)

191

Now I'm somewhat wondering about the things in pylab that are not in
pyplot nor in numpy.
E.g.:
pyplot.log2 is not numpy.log2
or
pyplot.window_hanning vs. numpy.hanning
or
pyplot.chisquare (which however is in numpy.random)

In summary, could one say that some functions are "left" in pylab to
keep backwards- and/or Matlab- compatibility ?
But does window_hanning behave exactly like numpy.hanning ?

I remember that some functions where decidedly implemented differently
than in numpy -- (sqrt for sqrt(-1) => 1j -- or was this scipy vs.
numpy)

Cheers,
Sebastian

···

On Fri, Jun 12, 2009 at 11:21 AM, Matthias Michler<MatthiasMichler@...361...> wrote:

On Friday 12 June 2009 10:49:52 Sebastian Haase wrote:

Hi,
long time ago there was a discussion on reducing the duplications of
functions / symbols between Numpy and Matplotlib.

I think from this resulted the pylab module now having many fewer entries:
>>> import matplotlib
>>> matplotlib.__version__

'0.98.5.2'

>>> import pylab
>>> len(pylab.__dict__)

882

However, I think these are still to many ! I wrote, already before
the cleanup, a "HACK"-cleanup routine, which makes a cut-down modules
(called P) like this:
# P = new.module("pylab_sparse","""pylab module minus stuff alreay in
numpy""") for k,v in pylab.__dict__.iteritems():
try:
if k[:2] == '__' or v is numpy.__dict__[k]:
continue
except KeyError:
pass
#P.__dict__[k] = v
exec("%s = pylab.%s" % (k,k))

((the commented out lines did not work, but they might still
illustrate what I want to do -- now I have this code in a separate
module that I can import as "P"

This way I get:
>>> len(P.__dict__)

395

>>> numpy.__version__

'1.3.0'

So why are there still that many -- more than half ! -- duplications
between pylab and numpy ?

Regards,

Sebastian Haase

These symbols are not in svn:

In [59]: plt.log2

···

On Fri, Jun 12, 2009 at 6:10 AM, Sebastian Haase<seb.haase@...287...> wrote:

On Fri, Jun 12, 2009 at 11:21 AM, Matthias > Michler<MatthiasMichler@...361...> wrote:

Hi Sebastian,

You are right. A large number of numpy functions is part of pylab, but I think
this problem was solved by introducing matplotlib.pyplot, which holds all
plotting functions of matplotlib. The module pylab imports these plotting
functions and all the numpy-stuff in order to offer plotting + numerical
functions by one import.

kind regards Matthias

Matthias,
thanks for the info. thats the info I was missing.

from matplotlib import pyplot
len(pyplot.__dict__)

191

Now I'm somewhat wondering about the things in pylab that are not in
pyplot nor in numpy.
E.g.:
pyplot.log2 is not numpy.log2
or
pyplot.window_hanning vs. numpy.hanning
or
pyplot.chisquare (which however is in numpy.random)

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

In [60]: plt.window_hanning
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in ?
AttributeError: 'module' object has no attribute 'window_hanning'

Sorry - I meant pylab ! not pyplot ...
There are those symbols.

-S.

···

On Fri, Jun 12, 2009 at 2:01 PM, John Hunter<jdh2358@...287...> wrote:

On Fri, Jun 12, 2009 at 6:10 AM, Sebastian Haase<seb.haase@...287...> wrote:

On Fri, Jun 12, 2009 at 11:21 AM, Matthias >> Michler<MatthiasMichler@...361...> wrote:

Hi Sebastian,

You are right. A large number of numpy functions is part of pylab, but I think
this problem was solved by introducing matplotlib.pyplot, which holds all
plotting functions of matplotlib. The module pylab imports these plotting
functions and all the numpy-stuff in order to offer plotting + numerical
functions by one import.

kind regards Matthias

Matthias,
thanks for the info. thats the info I was missing.

from matplotlib import pyplot
len(pyplot.__dict__)

191

Now I'm somewhat wondering about the things in pylab that are not in
pyplot nor in numpy.
E.g.:
pyplot.log2 is not numpy.log2
or
pyplot.window_hanning vs. numpy.hanning
or
pyplot.chisquare (which however is in numpy.random)

These symbols are not in svn:

In [59]: plt.log2
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in ?
AttributeError: 'module' object has no attribute 'log2'

In [60]: plt.window_hanning
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in ?
AttributeError: 'module' object has no attribute 'window_hanning'

Hi Sebastian, Hi list,

I'm not the one to decide this, but I think it is worth to try to remove
matplotlib.mlab routines, if their numpy counterparts provide the same
functionality or do I miss anything? After doing this one additionally could
clean up the imports in pylab in order to have only one call "from
matplotlib.mlab import" instead of 3.

kind regards Matthias

···

On Friday 12 June 2009 14:41:28 Sebastian Haase wrote:

On Fri, Jun 12, 2009 at 2:01 PM, John Hunter<jdh2358@...287...> wrote:
> On Fri, Jun 12, 2009 at 6:10 AM, Sebastian Haase<seb.haase@...287...> wrote:
>> On Fri, Jun 12, 2009 at 11:21 AM, Matthias > >> > >> Michler<MatthiasMichler@...361...> wrote:
>>> Hi Sebastian,
>>>
>>> You are right. A large number of numpy functions is part of pylab, but
>>> I think this problem was solved by introducing matplotlib.pyplot, which
>>> holds all plotting functions of matplotlib. The module pylab imports
>>> these plotting functions and all the numpy-stuff in order to offer
>>> plotting + numerical functions by one import.
>>>
>>> kind regards Matthias
>>
>> Matthias,
>> thanks for the info. thats the info I was missing.
>>
>>>>> from matplotlib import pyplot
>>>>> len(pyplot.__dict__)
>>
>> 191
>>
>> Now I'm somewhat wondering about the things in pylab that are not in
>> pyplot nor in numpy.
>> E.g.:
>> pyplot.log2 is not numpy.log2
>> or
>> pyplot.window_hanning vs. numpy.hanning
>> or
>> pyplot.chisquare (which however is in numpy.random)
>
> These symbols are not in svn:
>
>
> In [59]: plt.log2
> ------------------------------------------------------------
> Traceback (most recent call last):
> File "<ipython console>", line 1, in ?
> AttributeError: 'module' object has no attribute 'log2'
>
>
> In [60]: plt.window_hanning
> ------------------------------------------------------------
> Traceback (most recent call last):
> File "<ipython console>", line 1, in ?
> AttributeError: 'module' object has no attribute 'window_hanning'

Sorry - I meant pylab ! not pyplot ...
There are those symbols.

-S.

Matthias Michler wrote:

Hi Sebastian, Hi list,

I'm not the one to decide this, but I think it is worth to try to remove matplotlib.mlab routines, if their numpy counterparts provide the same functionality or do I miss anything? After doing this one additionally could

We have been doing this via deprecations. If there is something we have missed--a function in mlab that is also in numpy and that is *not* deprecated in mlab--please be specific about what it is, and we will deprecate it.

The functions like log2 are historical, part of a set contributed by Fernando Perez a long time ago. We tend to be cautious about ripping out such things, because user code may be depending on them. Maybe some of them should be deprecated. It is often hard to decide where and how to compromise between cleaning things up and maintaining backwards compatibility, just in case someone's code is depending on something obscure that has been there from early days.

If there are *specific* recommendations about functions that should be deprecated or changed, we would be happy to consider those recommendations.

clean up the imports in pylab in order to have only one call "from matplotlib.mlab import" instead of 3.

Yes, I see now that the mlab imports in pylab are an incredibly ugly mess and desperately need to be cleaned up. Thanks for pointing that out.

Multiple calls to "from matplotlib.mlab import ..." are fine with me, but I hate backslash line continuations, and I see that some functions are imported more than once.

It looks like we must be importing nearly everything, in which case it would be better to simply import * and then delete a few things if we really don't want them. A more radical change, such as importing only a very few things, and/or breaking mlab up so as to separate out the parts that pylab needs to import, may be better.

Eric

···

kind regards Matthias

On Friday 12 June 2009 14:41:28 Sebastian Haase wrote:

On Fri, Jun 12, 2009 at 2:01 PM, John Hunter<jdh2358@...287...> wrote:

On Fri, Jun 12, 2009 at 6:10 AM, Sebastian Haase<seb.haase@...287...> > wrote:

On Fri, Jun 12, 2009 at 11:21 AM, Matthias >>>> >>>> Michler<MatthiasMichler@...361...> wrote:

Hi Sebastian,

You are right. A large number of numpy functions is part of pylab, but
I think this problem was solved by introducing matplotlib.pyplot, which
holds all plotting functions of matplotlib. The module pylab imports
these plotting functions and all the numpy-stuff in order to offer
plotting + numerical functions by one import.

kind regards Matthias

Matthias,
thanks for the info. thats the info I was missing.

from matplotlib import pyplot
len(pyplot.__dict__)

191

Now I'm somewhat wondering about the things in pylab that are not in
pyplot nor in numpy.
E.g.:
pyplot.log2 is not numpy.log2
or
pyplot.window_hanning vs. numpy.hanning
or
pyplot.chisquare (which however is in numpy.random)

These symbols are not in svn:

In [59]: plt.log2
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in ?
AttributeError: 'module' object has no attribute 'log2'

In [60]: plt.window_hanning
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in ?
AttributeError: 'module' object has no attribute 'window_hanning'

Sorry - I meant pylab ! not pyplot ...
There are those symbols.

-S.

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users