我正在由curveSeq持有的给定的Y值序列创建一个图形. (X值自动枚举:0,1,2 …)
即对于curveSeq = [10,20,30],我的图表将包含以下几点:
<0,10>,<1,20>,<2,30>.
我在同一个nx.Graph上绘制了一系列图表,以便将一切都放在一张照片中.
我的问题是:
>每个节点显示其位置.即位置< 0,10>中的节点呈现各自的标签,我不知道如何删除它.
>有特定的节点,我想添加一个标签,但我不知道如何.
例如,序列:
[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
收到的图是:
代码是:
for point in curveSeq: cur_point = point #assert len(cur_point) == 2 if prev_point is not None: # Calculate the distance between the nodes with the Pythagorean # theorem b = cur_point[1] - prev_point[1] c = cur_point[0] - prev_point[0] a = math.sqrt(b ** 2 + c ** 2) G.add_edge(cur_point,prev_point,weight=a) G.add_node(cur_point) pos[cur_point] = cur_point prev_point = cur_point #key: G.add_node((curve+1,-1)) pos[(curve+1,-1)] = (curve+1,-1) nx.draw(G,pos=pos,node_color = colors[curve],node_size=80) nx.draw_networkx_edges(G,alpha=0.5,width=8,edge_color=colors[curve]) plt.savefig(currIteration+'.png')