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()
这是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 9] node[ ID 10] node[ ID 11]edge[ source 1 target 2]edge[ source 1 target 2]edge[ source 1 target 3]edge[ source 1 target 4]edge[ source 1 target 5]edge[ source 2 target 3]edge[ source 2 target 4]edge[ source 2 target 5]edge[ source 3 target 4]edge[ source 3 target 5]edge[ source 4 target 5]edge[ source 6 target 7]edge[ source 6 target 8]edge[ source 6 target 9]edge[ source 6 target 10]edge[ source 7 target 8]edge[ source 7 target 9]edge[ source 7 target 10]edge[ source 8 target 9]edge[ source 8 target 10]edge[ source 9 target 10]edge[ source 5 target 6]edge[ source 5 target 11] edge [ source 6 target 11 ]]解决方法 由于我没有您的数据,我在networx主页上使用了 this simple example.但是在你的代码中使用它应该是微不足道的.
import matplotlib.pyplot as pltimport networkx as nxG=nx.star_graph(20)pos=nx.spring_layout(G)colors=range(20)cmap=plt.cm.Bluesvmin = min(colors)vmax = max(colors)nx.draw(G,pos,node_color='#A0CBE2',edge_color=colors,wIDth=4,edge_cmap=cmap,with_labels=False,vmin=vmin,vmax=vmax)sm = plt.cm.ScalarMappable(cmap=cmap,norm=plt.normalize(vmin = vmin,vmax=vmax))sm._A = []plt.colorbar(sm)plt.show()
这样做的伎俩,但我同意,nx.draw只返回None有点可悲.
总结以上是内存溢出为你收集整理的如何在python中添加一个简单的“colorbar”到网络图?全部内容,希望文章能够帮你解决如何在python中添加一个简单的“colorbar”到网络图?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)