我想知道如何在我的情节中添加一个颜色条.我必须遵循代码,通过读取gml文件绘制图形.我有一组数字作为颜色分配给边缘,我只想在图表旁边看到一个颜色条,这样我就可以分析颜色了.当我添加plt.colorbar(g)它给我错误.如何在不经历实际构建色条的所有过程的情况下添加色条?
H = nx.read_gml('./network1.gml')
EAM = EigenVectorCentrality( EAMatrix );
x = [];
for eam in EAM[0]:
x.append(eam[0]);
degs = H.degree().values();
plt.clf()
g = nx.draw(H, with_labels=0, edge_color=x, node_size=70, font_size=9, width=1)
plt.axis('equal')
plt.colorbar(g);
plt.show()
Run Code Online (Sandbox Code Playgroud)
这是Nerwork1.gml文件:
graph
[
node
[
id 1
]
node
[
id 2
]
node
[
id 3
]
node
[
id 4
]
node
[
id 5
]
node
[
id 6
]
node
[
id 7
]
node
[
id 8
]
node
[
id …Run Code Online (Sandbox Code Playgroud)