Drawing graphs giving node coordinates

1,229 views
Skip to first unread message

Salvo Scellato

unread,
Apr 1, 2008, 12:54:56 PM4/1/08
to networkx...@googlegroups.com
Hi all,
I am using pygraphviz to draw a network giving all the node
coordinates in a 2-D space.

Is there any way to do the same using only networkx??

Thanks in advance!

--
Salvatore Scellato

Scuola Superiore di Catania
University of Catania
Website: http://www.ssc.unict.it/~sascellato/

Aric Hagberg

unread,
Apr 1, 2008, 1:28:10 PM4/1/08
to networkx...@googlegroups.com
On Tue, Apr 01, 2008 at 05:54:56PM +0100, Salvo Scellato wrote:
> I am using pygraphviz to draw a network giving all the node
> coordinates in a 2-D space.
>
> Is there any way to do the same using only networkx??

No and yes. NetworkX alone doesn't provide any drawing capabilities
but in addition to pygraphviz (for the interface to graphviz)
there is an interface to matplotlib/pylab.

There are some graph layout algorithms built into networkx (they
require the python package numpy).

Alternatively you can write the graph to a file format that is
understood by some other graph drawing software (e.g. dot format).

>>> import networkx
>>> G=networkx.path_graph(4)
>>> pos1=networkx.spring_layout(G) # spring layout - uses numpy
>>> xy=zip(range(4),range(4))
>>> pos2=dict(zip(G.nodes(),xy)) # custom layout
>>> pos3=networkx.graphviz_layout(G) # graphviz layout using 'neato'
>>> networkx.draw(G,pos1) # draw with pylab
>>> import pylab
>>> pylab.show()


Aric

Salvo Scellato

unread,
Apr 1, 2008, 6:47:46 PM4/1/08
to networkx...@googlegroups.com
On Tue, Apr 1, 2008 at 6:28 PM, Aric Hagberg <hag...@lanl.gov> wrote:
> No and yes. NetworkX alone doesn't provide any drawing capabilities
> but in addition to pygraphviz (for the interface to graphviz)
> there is an interface to matplotlib/pylab.
>
> There are some graph layout algorithms built into networkx (they
> require the python package numpy).
>
> Alternatively you can write the graph to a file format that is
> understood by some other graph drawing software (e.g. dot format).
>

Since I have (x,y) coordinates for each node I guess the best way to
do that is to write the graph to a file and then use something else...

Anyway, probably I will continue using pygraphviz.

Thank you!

Reply all
Reply to author
Forward
0 new messages