[Numpy-discussion] numpy array in networkx graph?

bob tnur bobtnur78 at gmail.com
Wed Jun 13 11:04:23 EDT 2012


I have M is numpy matrix with 0's& 1's. I want to color the nodes with
different colors.
can anyone give me a hint on the following code?

import network as nx
import pylab as plt

G=nx.Graph(M)  # M is numpy matrix ,i.e:type(M)=numpy.ndarray
for i in xrange(len(M)):
      tt=P[i,:].sum()
      if tt==1:
          G.add_node(i,color='blue')
      elif tt==2:
          G.add_node(i,color='red')
      elif tt==3:
          G.add_node(i,color='white')
      else:
          tt==4
          G.add_node(i,color='green')
G.nodes(data=True)
T=nx.draw(G)
plt.axis('off')
plt.savefig("test.png")

I didn't get color change, still the defualt color is used.Did I miss
something?

my aim is to obtain:
something like:
find total number of w-red-red-z path
           number of w-red-red-red-z path
           number of w-red-red-red-red-z path
where w (left side of some cyclic polygon(can also be conjugated ring))
and z(right-side of it)are any of the colors except red.

any comment is appreciated?
Thanks
Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120613/5edd81f7/attachment.html>


More information about the NumPy-Discussion mailing list