问题描述
我有一个使用NetworkX构造的简单图形,如下所示:
import networkx as nx
import matplotlib.pyplot作为plt
G = nx.DiGraph()
G.add_edges_from([(0,1),(0,2),(1,1),(1,2)] )
nx.draw_networkx(G)
plt.show()
当我画了这张图,我看到了这张图:
图也有一个边(1,1),但它不会在图像上显示这个边。我怎样才能画出这个边缘呢?我认为这是不使用箭头的结果。这种可视化非常糟糕。如何使用箭头代替粗线?
Graphviz在绘制箭头和自循环方面做得非常出色。 (在Matplotlib中实现的不平凡)。
下面是一个例子:
pre $ import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_edges_from(\ [(0,1),(0,2),(1,1),(1,2)\])
nx.write_dot(G,'graph.dot')
#然后运行dot -Tpng graph.dot> graph.png
I have a simple graph constructed using NetworkX as follows:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_edges_from([(0,1), (0,2), (1,1), (1,2)])
nx.draw_networkx(G)
plt.show()
When I draw this graph, I get this image:
The graph also has an edge (1,1) but it does not show this edge on image. How can i draw this edge, too? I think this is the result of not using arrows. This visualization is really very bad. How can I use arrows instead of this bold lines?
Graphviz does a great job of drawing arrows and self loops. (Non-trivial to implement in Matplotlib).Here is an example:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_edges_from(\[(0,1), (0,2), (1,1), (1,2)\])
nx.write_dot(G,'graph.dot')
# then run dot -Tpng graph.dot > graph.png
这篇关于如何在networkx图形绘制中显示周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!