[NetworkX-discuss] Problem using networkX-0.33 and python-matplotlib--0.87.3-1.fc5

274 views
Skip to first unread message

Tomi Hautakoski

unread,
Jan 22, 2007, 2:56:30 PM1/22/07
to networkx...@lists.sourceforge.net
Hello,

I just installed networkX and other tools to produce some graphs but I'm
hitting a problem when trying out the examples from wiki:

Python 2.4.3 (#1, Oct 23 2006, 14:19:47)
[GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from networkx import *
>>> G=Graph()
>>> G.add_edges_from([(1,2),(1,3)])
>>> G.add_node(1)
>>> G.add_edge((1,2))
>>> G.add_node("spam")
>>> draw(G)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/networkx/drawing/nx_pylab.py",
line 129, in draw
draw_networkx(G, pos, ax=ax, with_labels=with_labels, **kwds)
File "/usr/lib/python2.4/site-packages/networkx/drawing/nx_pylab.py",
line 169, in draw_networkx
node_collection=draw_networkx_nodes(G, pos, ax=ax, **kwds)
File "/usr/lib/python2.4/site-packages/networkx/drawing/nx_pylab.py",
line 208, in draw_networkx_nodes
xy=asarray([pos[v] for v in nodelist],dtype='d')
TypeError: asarray() got an unexpected keyword argument 'dtype'
>>> draw_random(G)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/networkx/drawing/nx_pylab.py",
line 429, in draw_random
draw(G,random_layout(G),**kwargs)
File "/usr/lib/python2.4/site-packages/networkx/drawing/nx_pylab.py",
line 129, in draw
draw_networkx(G, pos, ax=ax, with_labels=with_labels, **kwds)
File "/usr/lib/python2.4/site-packages/networkx/drawing/nx_pylab.py",
line 169, in draw_networkx
node_collection=draw_networkx_nodes(G, pos, ax=ax, **kwds)
File "/usr/lib/python2.4/site-packages/networkx/drawing/nx_pylab.py",
line 208, in draw_networkx_nodes
xy=asarray([pos[v] for v in nodelist],dtype='d')
TypeError: asarray() got an unexpected keyword argument 'dtype'
>>>

System used is a FC5, only pygraphviz and networkX are from sources. All
the other stuff is from rpms. Anyone has any suggestions what might be
wrong here?

Thanks for any hints,

Tomi Hautakoski
tha...@iki.fi
Why are there interstate highways in Hawaii?

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NetworkX-discuss mailing list
NetworkX...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/networkx-discuss

Steve Lianoglou

unread,
Jan 22, 2007, 3:35:34 PM1/22/07
to Tomi Hautakoski, networkx...@lists.sourceforge.net
Hi Tomi,

> I just installed networkX and other tools to produce some graphs
> but I'm
> hitting a problem when trying out the examples from wiki:

...


> xy=asarray([pos[v] for v in nodelist],dtype='d')
> TypeError: asarray() got an unexpected keyword argument 'dtype'
>
> System used is a FC5, only pygraphviz and networkX are from
> sources. All
> the other stuff is from rpms. Anyone has any suggestions what might be
> wrong here?

There might be a problem with your matplotlib/numpy packaging/version-
numbers.

There was recently an upheaval in the Python Numeric/Numpy scene,
which is now settling on using numpy as the standard array
library ... it recently hit v 1.0 which broke some backwards
compatibility and perhaps there's some versioning mismatch stuff
going on.

What do you have set for your matplotlib "numerix" library?

I'm not sure where you'll find this, you can try in ~/.matplotlib/
matplotlibrc

look for the 'numerix' value.

Also, fire up python and do:

import numpy as N
print N.__version__

and let us know what version it says there.

(I guess the version of matplotlib is relevant as well)

... or maybe matplotlib is set to use Numeric?

Well.. there's some stuff to get started. Hopefully that'll help us
figure out what's up.

-steve

Aric Hagberg

unread,
Jan 22, 2007, 3:37:45 PM1/22/07
to Tomi Hautakoski, networkx...@lists.sourceforge.net
Hi Tomi,

I think what is happening is that you are using Numeric
instead of numpy with matplotlib/pylab.
I tried to fix this in [501]
https://networkx.lanl.gov/changeset/501

You might try getting the subversion source and see if it works
for you. Else see if you can use matplotlib with numpy.
I'm not sure what the situation is with FC5 - you might be able
to set in your matplotlibrc file
%grep numerix .matplotlib/matplotlibrc
numerix : numpy # numpy, Numeric or numarray

Aric

Tomi Hautakoski

unread,
Jan 23, 2007, 2:22:16 PM1/23/07
to Steve Lianoglou, networkx...@lists.sourceforge.net
On Mon, 22 Jan 2007, Steve Lianoglou wrote:

> What do you have set for your matplotlib "numerix" library?

I upgraded networkx to todays svn version and added this line to my
matplotlibrc (had to create the file by hand):

numerix: numpy # numpy, Numeric or numarray

After this change, the following happens:


>>> from networkx import *
>>> G=Graph()
>>> G.add_edges_from([(1,2),(1,3)])
>>> G.add_node(1)
>>> G.add_edge((1,2))
>>> G.add_node("spam")
>>> draw(G)
Traceback (most recent call last):
File "<stdin>", line 1, in ?

NameError: name 'draw' is not defined
>>>

However, if I remove the line from my matplotlibrc, the error is a new
one:

>>> from networkx import *
>>> G=Graph()
>>> G.add_edges_from([(1,2),(1,3)])
>>> G.add_node(1)
>>> G.add_edge((1,2))
>>> G.add_node("spam")
>>> draw(G)
Traceback (most recent call last):
File "<stdin>", line 1, in ?

File "networkx/drawing/nx_pylab.py", line 126, in draw
draw_networkx(G, pos, ax=ax, **kwds)
File "networkx/drawing/nx_pylab.py", line 162, in draw_networkx
node_collection=draw_networkx_nodes(G, pos, **kwds)
File "networkx/drawing/nx_pylab.py", line 215, in draw_networkx_nodes
alpha=alpha)
File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line 3131,
in scatter
minx = amin(x)
File "/usr/lib/python2.4/site-packages/Numeric/MLab.py", line 152, in
min
return minimum.reduce(m,axis)
TypeError: function not supported for these types, and can't coerce to
supported types

Looks like at least without the numpy definition in the rc file, Numeric
is used. But how can it affect to networkx if I remove the line?

> Also, fire up python and do:
>
> import numpy as N
> print N.__version__

>>> import numpy as N
>>> print N.__version__

1.0.1
>>> import matplotlib as A
>>> A.__version__
'0.87.3'

Thanks for the answers so far, hopefully this is an easy case to fix. =)

Tomi Hautakoski
tha...@iki.fi
Thirty-nine is a nice age for a man, especially if he's over 40

Aric Hagberg

unread,
Jan 23, 2007, 2:36:08 PM1/23/07
to Tomi Hautakoski, networkx...@lists.sourceforge.net
On Tue, Jan 23, 2007 at 09:22:16PM +0200, Tomi Hautakoski wrote:
>
> numerix: numpy # numpy, Numeric or numarray
>
> After this change, the following happens:
> >>> from networkx import *
> >>> G=Graph()
> >>> G.add_edges_from([(1,2),(1,3)])
> >>> G.add_node(1)
> >>> G.add_edge((1,2))
> >>> G.add_node("spam")
> >>> draw(G)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> NameError: name 'draw' is not defined
> >>>

I'm guessing that matplotlib with numpy isn't working correctly.
(And thus networkx is silently failing to import the drawing code).

Could you check to make sure matplotlib works with numpy?

Aric

Steve Lianoglou

unread,
Jan 23, 2007, 3:04:43 PM1/23/07
to Aric Hagberg, networkx...@lists.sourceforge.net
> On Tue, Jan 23, 2007 at 09:22:16PM +0200, Tomi Hautakoski wrote:
>>
>> numerix: numpy # numpy, Numeric or numarray
>>
>> After this change, the following happens:
>>>>> from networkx import *
>>>>> G=Graph()
>>>>> G.add_edges_from([(1,2),(1,3)])
>>>>> G.add_node(1)
>>>>> G.add_edge((1,2))
>>>>> G.add_node("spam")
>>>>> draw(G)
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>> NameError: name 'draw' is not defined
>>>>>
>
> I'm guessing that matplotlib with numpy isn't working correctly.
> (And thus networkx is silently failing to import the drawing code).
>
> Could you check to make sure matplotlib works with numpy?

Yeah .. I'm pretty positive that you need matplotlib-0.87.7 to work
w/ numpy >= 1.0

There's a lot of installation woes regarding this issue on the numpy/
scipy mailing lists as well, but also it kind of says as much @ the
MPL website (http://matplotlib.sourceforge.net/)

Installing from source should be easy if you already have a previous
version of MPL installed (as it seems you do) ... you can just blow
out the old package-installed version and drop in the source-compiled
version ... I think the other depending libraries (backends and
things) should be just fine.

-steve

Tomi Hautakoski

unread,
Jan 23, 2007, 3:43:29 PM1/23/07
to networkx...@lists.sourceforge.net
On Tue, 23 Jan 2007, Steve Lianoglou wrote:

>> On Tue, Jan 23, 2007 at 09:22:16PM +0200, Tomi Hautakoski wrote:
>> I'm guessing that matplotlib with numpy isn't working correctly.
>> (And thus networkx is silently failing to import the drawing code).
>>
>> Could you check to make sure matplotlib works with numpy?

Sorry to bother you guys even more with this OT but how could I do test
this? Tried running this from the MPL's tutorial and it should use numpy.
The result for this is a correct picture so at least this case is ok.

from pylab import *
t = arange(0.0, 5.2, 0.2)

# red dashes, blue squares and green triangles
plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
show()

> Yeah .. I'm pretty positive that you need matplotlib-0.87.7 to work w/ numpy
>> = 1.0

OK, I removed the rpm and installed matplotlib-0.87.7 from the sources.
When running the same networkx test as before, now it just doesnt plot
anything:

...
>>> G.add_node("spam")
>>> draw(G)

Is there a way to debug what is (isnt) happening?

Tomi Hautakoski
tha...@iki.fi
Death is natures way of telling you to slow down.

Aric Hagberg

unread,
Jan 23, 2007, 4:25:45 PM1/23/07
to Tomi Hautakoski, networkx...@lists.sourceforge.net
On Tue, Jan 23, 2007 at 10:43:29PM +0200, Tomi Hautakoski wrote:
> On Tue, 23 Jan 2007, Steve Lianoglou wrote:
>
> Sorry to bother you guys even more with this OT but how could I do test
> this? Tried running this from the MPL's tutorial and it should use numpy.
> The result for this is a correct picture so at least this case is ok.
Good.

> ...
> >>> G.add_node("spam")
> >>> draw(G)
>
> Is there a way to debug what is (isnt) happening?

Can you try running this example?
https://networkx.lanl.gov/svn/networkx/trunk/doc/examples/draw_simple.py

It could be you need to issue a pylab.show() to draw the graph.

I'll see if I can get the drawing working correctly with Numeric too.
Aric

Tomi Hautakoski

unread,
Jan 24, 2007, 12:46:42 PM1/24/07
to networkx...@lists.sourceforge.net
On Tue, 23 Jan 2007, Aric Hagberg wrote:

>> ...
>>>>> G.add_node("spam")
>>>>> draw(G)
>>
>> Is there a way to debug what is (isnt) happening?
>
> Can you try running this example?
> https://networkx.lanl.gov/svn/networkx/trunk/doc/examples/draw_simple.py

It works!

> It could be you need to issue a pylab.show() to draw the graph.
>
> I'll see if I can get the drawing working correctly with Numeric too.

Yes, with my system that 'pylab.show()' is mandatory to get the picture
visible. Thank you everyone for the great advice on installing networkx
and MPL. Now I can start learning this very promising tool. =)


Tomi Hautakoski
tha...@iki.fi
It's not the principle of the thing, it's the money

Reply all
Reply to author
Forward
0 new messages