matplotlib.numerix

519 views
Skip to first unread message

dieterv77

unread,
Aug 12, 2009, 8:58:53 AM8/12/09
to networkx-discuss
Hi, first of all, thanks to those of you who contribute to this
excellent python package.

I noticed with both 0.99 and 1.0-dev* that i get deprecation warnings
from matplotlib regarding the numerix module which will be removed
from matplotlib at some point. These warnings only come up with more
recent
versions of matplotlib, such 0.98.5 or 0.99.0.

I looked at some of the source briefly, and it seems that in most
places one should
be able to replace references to matplotlib.numerix.mlab and
matplotlib.numerix
with numpy instead. One could even stagger the imports to check if
numpy is
available to maintain backward compatibility for users who do not have
numpy.
I haven't done a thorough search though so it is possible that in some
places the
replacement would not be so straightforward.

apologies if this has already been discussed.

thanks very much
dieter

Aric Hagberg

unread,
Aug 12, 2009, 9:37:35 AM8/12/09
to networkx...@googlegroups.com
On Wed, Aug 12, 2009 at 6:58 AM, dieterv77<diet...@gmail.com> wrote:
>
> I noticed with both 0.99 and 1.0-dev* that i get deprecation warnings
> from matplotlib regarding the numerix module which will be removed
> from matplotlib at some point.  These warnings only come up with more
> recent
> versions of matplotlib, such 0.98.5 or 0.99.0.
>
> I looked at some of the source briefly, and it seems that in most
> places one should
> be able to replace references to matplotlib.numerix.mlab and
> matplotlib.numerix
> with numpy instead.  One could even stagger the imports to check if
> numpy is
> available to maintain backward compatibility for users who do not have
> numpy.
> I haven't done a thorough search though so it is possible that in some
> places the
> replacement would not be so straightforward.
>

Thanks for pointing that out.

I think the best thing to do is to replace those cases with the
corresponding numpy functions.

Aric

dieterv77

unread,
Aug 12, 2009, 11:12:55 AM8/12/09
to networkx-discuss
Here's a diff that does the staggered import.
seems to work for me, at least when i ran a bunch of the drawing
examples. Maybe not the cleanest thing, but it touched the fewest
lines
of code :) If you'd rather just have a direct numpy import i can do
that as well
and send along a diff (or if it's easy to setup, commit to svn)

--- nx_pylab.py.orig 2009-08-12 09:23:16.000000000 -0400
+++ nx_pylab.py 2009-08-12 09:30:18.000000000 -0400
@@ -206,7 +206,10 @@
"""
try:
import matplotlib.pylab as pylab
- import matplotlib.numerix as nmex
+ try:
+ import numpy as nmex
+ except ImportError:
+ import matplotlib.numerix as nmex
except ImportError:
raise ImportError, "Matplotlib required for draw()"
except RuntimeError:
@@ -285,11 +288,17 @@
try:
import matplotlib
import matplotlib.pylab as pylab
- import matplotlib.numerix as nmex
+ try:
+ import numpy as nmex
+ except ImportError:
+ import matplotlib.numerix as nmex
import matplotlib.cbook as cb
from matplotlib.colors import colorConverter,Colormap
from matplotlib.collections import LineCollection
- import matplotlib.numerix.mlab as mlab
+ try:
+ import numpy as mlab
+ except ImportError:
+ import matplotlib.numerix.mlab as mlab
except ImportError:
raise ImportError, "Matplotlib required for draw()"
except RuntimeError:
@@ -519,7 +528,10 @@
"""
try:
import matplotlib.pylab as pylab
- import matplotlib.numerix as nmex
+ try:
+ import numpy as nmex
+ except ImportError:
+ import matplotlib.numerix as nmex
import matplotlib.cbook as cb
except ImportError:
raise ImportError, "Matplotlib required for draw()"


On Aug 12, 9:37 am, Aric Hagberg <aric.hagb...@gmail.com> wrote:

Aric Hagberg

unread,
Aug 12, 2009, 12:21:40 PM8/12/09
to networkx...@googlegroups.com
On Wed, Aug 12, 2009 at 9:12 AM, dieterv77<diet...@gmail.com> wrote:
>
> Here's a diff that does the staggered import.
> seems to work for me, at least when i ran a bunch of the drawing
> examples.  Maybe not the cleanest thing, but it touched the fewest
> lines
> of code :)  If you'd rather just have a direct numpy import i can do
> that as well
> and send along a diff (or if it's easy to setup, commit to svn)

I removed the numerix references and replaced them with numpy.
This will break this code for some people with very old versions
of matplotlib.

Can you take a look and make sure I fixed it properly?
https://networkx.lanl.gov/trac/changeset/1369

Aric

dieterv77

unread,
Aug 12, 2009, 2:43:53 PM8/12/09
to networkx-discuss
Worked great for me.
thanks a lot for such a quick response.

dieter

On Aug 12, 12:21 pm, Aric Hagberg <aric.hagb...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages