标题:python画图,运行出错,麻烦解决一下
只看楼主
一枚小团子
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-9-3
 问题点数:0 回复次数:0 
python画图,运行出错,麻烦解决一下
源代码如下:
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
edge=np.loadtxt("hust_edge.txt",delimiter=',')
node=np.loadtxt("hust_node.txt",delimiter=',')
hust_roads=nx.Graph()
hust_roads.clear()
vnlist=list(node[:,0])
vnodes=[]
for j in range(len(node[:,0])):
    vnodes.append((node[j,1],node[j,2]))
vedges=[]
edge_to_start=list(edge[:,0])
edge_to_end=list(edge[:,3])
for i in range(len(edge[:,2])):
    vedges.append((edge_to_start[i],edge_to_end[i]))
hust_roads.add_edges_from(vedges)
vpos=dict(zip(vnlist,vnodes))
nx.draw_networkx_nodes(hust_roads,vpos,vnlist,node_size=1,node_color='b',with_labels=True)#画出坐标对应的节点
nx.draw_networkx_edges(hust_roads,vpos,vedges)#画出节点对应的边
plt.show()
错误如下:
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-2-9d76c4115ef9> in <module>
     18 vpos=dict(zip(vnlist,vnodes))
     19 nx.draw_networkx_nodes(hust_roads,vpos,vnlist,node_size=1,node_color='b',with_labels=True)#画出坐标对应的节点
---> 20 nx.draw_networkx_edges(hust_roads,vpos,vedges)#画出节点对应的边
     21 plt.show()

/Applications/anaconda3/envs/ox/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py in draw_networkx_edges(G, pos, edgelist, width, edge_color, style, alpha, arrowstyle, arrowsize, edge_cmap, edge_vmin, edge_vmax, ax, arrows, label, node_size, nodelist, node_shape, connectionstyle, **kwds)
    575
    576     # set edge positions
--> 577     edge_pos = np.asarray([(pos[e[0]], pos[e[1]]) for e in edgelist])
    578
    579     if not cb.iterable(width):

/Applications/anaconda3/envs/ox/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py in <listcomp>(.0)
    575
    576     # set edge positions
--> 577     edge_pos = np.asarray([(pos[e[0]], pos[e[1]]) for e in edgelist])
    578
    579     if not cb.iterable(width):

KeyError: 1203937286.0
拜托大家帮忙解决一下!
搜索更多相关主题的帖子: for edge node 节点 对应 
2019-09-03 20:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-496676-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.588167 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved