【问题标题】:How can I set the sizes of nodes when using graphviz on python?在 python 上使用 graphviz 时如何设置节点的大小?
【发布时间】:2016-07-17 23:17:24
【问题描述】:

我现在使用 python 2.7 和 graphviz 从我的数据集中绘制类似集群的图。 每个簇都用这种类型表示-->[avg, num] 其中“avg”代表该簇中点的平均值 而“num”代表这个簇中的点数

我想创建一个图,每个节点都有不同的大小,这取决于“num”变量,就像我们可以用 networkx 做的一样

node_sizes = []
for n in nodes:
    node_sizes.append( 100 * n )
g = nx.Graph()
g.add_nodes_from(nodes)
nx.draw_random(g, node_size = node_sizes)

我使用graphviz而不使用networkx的原因是因为我真的不想手动设置节点的位置,graphviz中的neato或circo等引擎真的很有帮助。

感谢所有 cmets 和帮助。 T^T

【问题讨论】:

    标签: python plot graphviz


    【解决方案1】:

    您可以设置节点的大小如下:

    import graphviz as gv
    g = gv.Graph(format='png')
    for i in range(5):
        g.node(str(i), **{'width':str(i), 'height':str(i)})
    g.render('example')
    

    哪些产品:

    【讨论】:

    • 哇!我以为宽度和高度适用于矩形节点大声笑非常感谢你!!!
    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 2021-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    相关资源
    最近更新 更多