NOTE -- This is a complete rewrite of the previous question, which I think was too complex. It presents a much simpler version which, if I can solve, will result in progress.
I have adapted my code from this SO answer: Is there a way to guarantee hierarchical output from NetworkX?
With the following very simple code, I get strange coloring behavior.
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_node("ROOT")
for i in xrange(1):
for j in range(1):
G.add_node(str(j)+"_%i" % i, )
if j ==0:
G.add_edge("ROOT", str(j)+"_%i" % i)
else:
G.add_edge(str(j-1)+"_%i" %i, str(j)+"_%i" % i)
pos=nx.graphviz_layout(G,prog='dot')
for i in xrange(1):
nodelist = ['ROOT']
for j in range(1):
nodelist.append(str(j)+"_%i" % i )
nx.draw_networkx_nodes(G,pos, nodelist=nodelist, cmap=plt.get_cmap('Set3'), node_color=[0,1])
nx.draw_networkx_edges(G, pos,arrows=True)
limits=plt.axis('off')
It seems to NOT matter what values I give for the node_color
, only whether the values are different or not. For example, with node_color = [0,1]
, I get the exact same behavior as when it is [0,.1]
, or [0,1000]
. (Why? The colormap takes values between 0 and 1).
However if I change the colormap, the colors DO change. For example:
And if I set node_color = [3,3]
(or any two values which are the same), I always get the same thing, the nodes are colored identically.
Any ideas what I'm doing wrong here?