I have an adjacency matrix A and an array defining the coordinates of each node:
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
%matplotlib inline
Import adjacency matrix A[i,j]
A = 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 is to draw the graph displaying how the nodes are connect between one another. Therefore each edge should have an arrow or bidirectional arrow showing what direction to proceed along it.
I was able to display the connectivity but there are no arrows even though I specified the parameter as True.
## Draw newtwork
G = nx.from_numpy_matrix(A, xy)
nx.draw_networkx(G, pos=xy, width=3, arrows=True)
Can you please suggest me a way to achieve my goal without modifying the input data (A and xy)?

At some point, I got very annoyed at the lack of proper arrow support in the networkx drawing facilities and wrote my own, while keeping the API pretty much the same. Code can be found here.
import numpy as np
import netgraph
A = 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]])
xy = np.array([[0, 0],
[-20, 20],
[17, 27],
[-6, 49],
[15, 65],
[-20, 76],
[5, 100]])
N = len(A)
node_labels = dict(zip(range(N), range(N)))
netgraph.draw(np.array(A), xy / np.float(np.max(xy)), node_labels=node_labels)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With