Network graph not showing arrows along edge in Python -
i have adjacency matrix , array defining coordinates of each node:
import numpy np import matplotlib.pyplot plt import networkx nx %matplotlib inline import adjacency matrix a[i,j] = np.matrix([[0, 1, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0]]) ## import node coordinates xy = np.array([[0, 0], [-20, 20], [17, 27], [-6, 49], [15, 65], [-20, 76], [5, 100]]) my goal draw graph displaying how nodes connect between 1 another. therefore each edge should have arrow or bidirectional arrow showing direction proceed along it.
i able display connectivity there no arrows though specified parameter true.
## draw newtwork g = nx.from_numpy_matrix(a, xy) nx.draw_networkx(g, pos=xy, width=3, arrows=true) can please suggest me way achieve goal without modifying input data (a , xy)?
i managed "arrows". digging around on other stack overflow questions (here, , here) seems best way arrows using matplotlib.
import numpy np import networkx nx import matplotlib.pyplot plt #import adjacency matrix a[i,j] = np.matrix([[0, 1, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0]]) ## import node coordinates xy = np.array([[0, 0], [-20, 20], [17, 27], [-6, 49], [15, 65], [-20, 76], [5, 100]]) g = nx.from_numpy_matrix(np.array(a), create_using = nx.multidigraph()) pos = xy nx.draw(g,pos) labels = {i: + 1 in g.nodes()} nx.draw_networkx_labels(g, pos, labels, font_size=15, arrows=true) plt.show() 

Comments
Post a Comment