python绘制多图 [英] python draw multigraph
问题描述
我尝试使用graphviz在Python中绘制多图。
现在我可以在Python中绘制通常的图表,例如:
import pygraphviz as pgv
G = pgv.AGraph()
G.add_node('a')
G.add_node('b')
G.layout()
G.add_edge('a','b','first')
G.add_edge('a','b','second')
sorted(G.edges(keys = True))
G.draw('file.png')
在输出:
但实际上我希望得到多图,即
但文档仍然应该区分:
我不知道绘制多图,但不只是图。
感谢您的任何帮助。
似乎在python中还没有这样的库可以实现它,所以我使用Wolfram Mathematica来完成它。但问题仍然是打开的。
加法
现在工作代码看起来如此:
pre $
import pygraphviz as pgv
G = pgv.AGraph(strict = False)
G.add_node( 'a')
G.add_node('b')
G.layout()
G.add_edge('a','b','first')
G .add_edge('a','b','second')
sorted(G.edges(keys = True))
G.draw('file.png')
解决方案正如您引用的文档所述,您需要指定 strict = False
创建多边图形时。由于您没有这样做,您的图形不支持平行边缘。
I try to draw multigraph in Python using graphviz.
For now I can draw usual graphs in Python somehow like:
import pygraphviz as pgv
G=pgv.AGraph()
G.add_node('a')
G.add_node('b')
G.layout()
G.add_edge('a','b','first')
G.add_edge('a','b','second')
sorted(G.edges(keys=True))
G.draw('file.png')
And I get on the output:
But actually I want get multigraph, i.e.
But documentation stays that it should differentiate :
I have no idea about drawing multigraph but not just graph.
Thanks for any help.
Addition:
it seems that there are no yet such libraries in python that can do it, so I did it using Wolfram Mathematica. But question is still opened.
Addition
Now working code looks so:
import pygraphviz as pgv
G=pgv.AGraph(strict=False)
G.add_node('a')
G.add_node('b')
G.layout()
G.add_edge('a','b','first')
G.add_edge('a','b','second')
sorted(G.edges(keys=True))
G.draw('file.png')
解决方案 As the documentation you quoted says, you need to specify strict=False
when creating a multi-edge graph. Since you didn't do this your graph doesn't support parallel edges.
这篇关于python绘制多图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!