繁体   English   中英

Python.networkx - 如何绘制带标签的图形

[英]Python networkx - How to draw graph with labels

from graphviz import *
import networkx as nx
from networkx import *
import matplotlib.pyplot as plt

    G = nx.DiGraph()
    G.add_node(1)
    G.add_node(2)
    G.add_edge(1,2)
    myLabels = {1: 'node1', 2: 'node2'}
    nx.set_node_attributes(G, myLabels, 'label')
    nx.draw(G,with_labels=True)

所以目前我使用最新的.networkx。 当我使用 nx.draw(G, with_values=True) 时,它使用顶点索引而不是标签。

我怎样才能解决这个问题? 谢谢你。

图片应该是 node1, node2

更改此命令: nx.draw(G,with_labels=True)nx.draw(G,with_labels=True, labels = myLabels)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM