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
拜托大家帮忙解决一下!