当我运行这个例子时:
import networkx as nx
import matplotlib.pyplot as plt
B=[[0,1],
[2,4],
[5,6],
[3,7],
[0,3]]
G = nx.Graph()
for i in range(len(B)):
G.add_edge((B[i][0]),(B[i][1]))
nx.draw(G,with_labels=True, node_color=[0,1,1,0,0,1,1,0])
plt.show()
显示图表。但是,当我添加更多边和节点颜色时,如下所示:
import networkx as nx
import matplotlib.pyplot as plt
B=[[0,1],
[2,4],
[5,6],
[3,7],
[0,3],
[2,8],
[7,11],
[6,10],
[3,12],
[6,12]]
G = nx.Graph()
for i in range(len(B)):
G.add_edge((B[i][0]),(B[i][1]))
nx.draw(G,with_labels=True, node_color=[0,1,1,0,0,1,1,0,1,0,1,1,1])
plt.show()
它引发了这个错误。
ValueError: to_rgba: Invalid rgba arg "0"
to_rgb: Invalid rgb arg "0"
cannot convert argument to rgb sequence
我该如何解决这个问题?
答案 0 :(得分:0)
The error didn't seem instructive to the nature of the problem here, but it's simply that you have 12 nodes and 13 node colours. Remove one of the items in [0,1,1,0,0,1,1,0,1,0,1,1,1]
and the problem goes away.