Draw function

Hi,
I've a problem with the draw function.
I've tried to execute the python code available at the web-page
https://networkx.lanl.gov/wiki/file/networkx/trunk/doc/examples/draw_colors.py
It uses matplotlib + networkx.

By executing this code, I receive the following error message:
File "draw_colors.py", line 27, in ?
  draw(G,pos,node_color=array([G.degree(v) for v in G]))
TypeError: draw() takes exactly 1 non-keyword argument (2 given)

By executing similar codes, I receive similar message.
It seems I have a problem with the draw function.

Can you help me to understand why I have this problem and how is it
possible to solve it?

I suppose it's related to the use of matplotlib more then to the use of
networkx.

Many thanks.

All the best,
Nic

(first reply mistakenly went only to Giandomenico)

Hi,

I have a guess. I didn't download NetworkX to give it a try, but both
pylab and networkx have draw() functions, and the example just does a
"from blah import *" for both. At a guess, the pylab draw() function
is clobbering the intended NetworkX draw() function. Try this:

try:
   import pylab # DON'T DO: from pylab import *
except:
   print "pylab not found: see https://networkx.lanl.gov/Drawing.html for info"
   raise

from networkx import *

G=grid_2d_graph(4,4) #4x4 grid
pos=spring_layout(G)
draw(G,pos,alpha=0.5,with_labels=False)
draw(G,pos,nodelist=[1,2,3,4],node_color='b') # blue
pylab.savefig("grid.png") # save as png
pylab.show() # display

···

File "draw_colors.py", line 27, in ?
  draw(G,pos,node_color=array([G.degree(v) for v in G]))
TypeError: draw() takes exactly 1 non-keyword argument (2 given)

--
Charles R. Twardy

Patient: doctor, it hurts when I do this.
Doctor: Then don't do that!

Charles R. Twardy wrote:

try:
   import pylab # DON'T DO: from pylab import *

...

from networkx import *

And don't do that either!

Namespaces are one honking great idea: let's do more of those!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Hi,
Many thanks.
I tried to use this new code, but nothing to do.
The error remains the same.
DO you have other suggestions please?
Thanks.
Nico

···

Il giorno mar, 10/01/2006 alle 14.20 -0500, Charles R. Twardy ha scritto:

(first reply mistakenly went only to Giandomenico)

Hi,

I have a guess. I didn't download NetworkX to give it a try, but both
pylab and networkx have draw() functions, and the example just does a
"from blah import *" for both. At a guess, the pylab draw() function
is clobbering the intended NetworkX draw() function. Try this:

try:
   import pylab # DON'T DO: from pylab import *
except:
   print "pylab not found: see https://networkx.lanl.gov/Drawing.html for info"
   raise

from networkx import *

G=grid_2d_graph(4,4) #4x4 grid
pos=spring_layout(G)
draw(G,pos,alpha=0.5,with_labels=False)
draw(G,pos,nodelist=[1,2,3,4],node_color='b') # blue
pylab.savefig("grid.png") # save as png
pylab.show() # display

> File "draw_colors.py", line 27, in ?
> draw(G,pos,node_color=array([G.degree(v) for v in G]))
> TypeError: draw() takes exactly 1 non-keyword argument (2 given)

--
Charles R. Twardy

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Nic,

I downloaded NetworkX from sourceforge and unpacked it. Then:
cd networkx-0.26
python setup.py build && sudo python setup.py install
cd doc/examples
python draw_colors.py

It ran fine.

I changed the code to avoid all the "import *". Try this?

#!/usr/bin/env python
"""
Draw a graph with matplotlib.
You must have matplotlib for this to work.
"""
__author__ = """Aric Hagberg (hagberg@...652...)"""
__date__ = "$Date: 2005-03-22 13:57:46 -0700 (Tue, 22 Mar 2005) $"
__credits__ = """"""
__revision__ = "$Revision: 831 $"
# Copyright (C) 2004 by
# Aric Hagberg <hagberg@...652...>
# Dan Schult <dschult@...945...>
# Pieter Swart <swart@...652...>
# Distributed under the terms of the GNU Lesser General Public License
# http://www.gnu.org/copyleft/lesser.html

try:
    import pylab
except:
    print "pylab not found: see https://networkx.lanl.gov/Drawing.html for info"
    raise

import networkx as net

G = net.grid_2d_graph(4,4) #4x4 grid
pos = net.spring_layout(G)
net.draw(G,pos,alpha=0.5,with_labels=False)
net.draw(G,pos,nodelist=[1,2,3,4],node_color='b') # blue
pylab.savefig("grid.png") # save as png
pylab.show() # display

···

--
Charles R. Twardy