I'm drawing to draw a simple undirected graph with networkx and I'm having trouble coloring the nodes according to a specific attribute. I created a dictionary, in which case the key references a list of nodes that contain that attribute. It looks like so:
{
1 : [1, 2, 3, 4],
3 : [9, 11, 10, 8],
2 : [7, 5, 6]
}
I would like to render the graph so that each set of nodes is colored differently. The keys are used to access a specific color. I draw the graph like so:
colors = [(random.random(), random.random(), random.random()) for i in xrange(0, 3)]
pos = nx.circular_layout(G)
for k,v in node_list_dict.iteritems():
nc = colors[int(k)-1]
nx.draw_networkx_nodes(G, pos, nodelist=v, node_color=nc)
nx.draw_networkx_edges(G, pos)
nx.draw_networkx_labels(G, pos)
This almost works, but results in an image like:
So it appears that the first two sets render correctly, but the last one does not. Any idea as to why? I looked at the documentation but I don't see why it's failing.
Also, the colors list usually ends up like so (when I mean usually I mean the colors generated are somewhat random)
[(0.982864745272968, 0.038693538759121182, 0.03869353875912118), (0.12848750206109338, 0.9956534627440381, 0.12848750206109338), (0.050388282183359334, 0.050388282183359334, 0.9916284269963801)]