Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用networkx的节点标签_Python_Matplotlib_Networkx - Fatal编程技术网

Python 使用networkx的节点标签

Python 使用networkx的节点标签,python,matplotlib,networkx,Python,Matplotlib,Networkx,我正在用curveSeq持有的给定Y值序列创建一个图形。(自动枚举X值:0,1,2…) i、 e对于curveSeq=[10,20,30],我的图表将包含以下几点: <0,10>, <1,20>, <2,30>. 收到的图形为: 代码是: for point in curveSeq: cur_point = point #assert len(cur_point) == 2

我正在用
curveSeq
持有的给定Y值序列创建一个图形。(自动枚举X值:0,1,2…)

i、 e对于
curveSeq=[10,20,30]
,我的图表将包含以下几点:

<0,10>, <1,20>, <2,30>.
收到的图形为:

代码是:

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,pos=pos,alpha=0.5,width=8,edge_color=colors[curve])

     plt.savefig(currIteration+'.png')

您可以添加
with_labels=False
关键字,以禁止使用
networkx.draw()
绘制标签,例如

networkx.draw(G, pos=pos, node_color=colors[curve],
    node_size=80, with_labels=False)
然后使用

networkx.draw_networkx_labels(G,pos, labels)
其中标签是将节点ID映射到标签的字典


看看这个例子:

链接断开了。改用这个:
networkx.draw_networkx_labels(G,pos, labels)