Question

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:

enter image description here

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?

Was it helpful?

Solution

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

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top