如何使用matplotlib或graphviz在networkx中绘制多图 [英] how to draw multigraph in networkx using matplotlib or graphviz
问题描述
当我将多图numpy邻接矩阵传递给networkx时(使用from_numpy_matrix函数) 然后尝试使用matplotlib绘制图形,它将忽略多个边.
我怎样才能使其绘制多个边缘?
Graphviz很好地绘制了平行边缘.您可以通过编写点文件,然后使用Graphviz处理(例如下面的neato布局),将其用于NetworkX.除了NetworkX,您还需要pydot或pygraphviz
In [1]: import networkx as nx
In [2]: G=nx.MultiGraph()
In [3]: G.add_edge(1,2)
In [4]: G.add_edge(1,2)
In [5]: nx.write_dot(G,'multi.dot')
In [6]: !neato -T png multi.dot > multi.png
在NetworkX 1.11及更高版本上, 或 when I pass multigraph numpy adjacency matrix to networkx (using from_numpy_matrix function)
and then try to draw the graph using matplotlib, it ignores the multiple edges. how can I make it draw multiple edges as well ? Graphviz does a good job drawing parallel edges. You can use that with NetworkX by writing a dot file and then processing with Graphviz (e.g. neato layout below). You'll need pydot or pygraphviz in addition to NetworkX On NetworkX 1.11 and newer, or 这篇关于如何使用matplotlib或graphviz在networkx中绘制多图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!nx.write_dot
不能按照networkx github上的问题.解决方法是使用write_dot
from networkx.drawing.nx_pydot import write_dot
from networkx.drawing.nx_agraph import write_dot
In [1]: import networkx as nx
In [2]: G=nx.MultiGraph()
In [3]: G.add_edge(1,2)
In [4]: G.add_edge(1,2)
In [5]: nx.write_dot(G,'multi.dot')
In [6]: !neato -T png multi.dot > multi.png
nx.write_dot
doesn't work as per issue on networkx github. The workaround is to call write_dot
usingfrom networkx.drawing.nx_pydot import write_dot
from networkx.drawing.nx_agraph import write_dot