Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing arrowhead type in networkx

I am plotting directed graph using networkx in python. However, I found that arrow head of edge is thick from one end instead of pointed arrow. I want to change the thick edge to pointed arrow. Here is my code, actual output, and desired output:

import networkx as nx
import matplotlib.pyplot as plt

G=nx.DiGraph()

item = [1,2]

G.add_edge(*item) #color = item[-1], weight = 2)

pos = nx.circular_layout(G)    
nx.draw(G, pos, with_labels = True, edge_color = 'b')   
plt.show()

Output enter image description here

Desired output: enter image description here

Any suggestion would be really helpful?

like image 849
user2293224 Avatar asked Nov 09 '17 23:11

user2293224


Video Answer


1 Answers

This may be a late answer, but in the new version networkx 2.1 you can set the arrow type by using the arrowstyle and arrowsize parameter.

import networkx as nx
import matplotlib.pyplot as plt

G=nx.DiGraph()

item = [1,2]

G.add_edge(*item) #color = item[-1], weight = 2)

pos = nx.circular_layout(G)    
nx.draw(G, pos, with_labels = True, edge_color = 'b', arrowsize=20, arrowstyle='fancy')   
plt.show()

You can go to the documentation for details: https://networkx.github.io/documentation/stable/reference/generated/networkx.drawing.nx_pylab.draw_networkx_edges.html#networkx.drawing.nx_pylab.draw_networkx_edges

like image 154
pilo Avatar answered Sep 18 '22 18:09

pilo