I have an undirected graph described by its adjacency matrix (a numpy array) and I want to plot it, with vertices placed in a n-regular polygon. This code works:
n = adyacency_mathix.shape[0]
axis = np.linspace(0, 2*np.pi, n, endpoint=False)
x, y = np.cos(axis), np.sin(axis)
for i in xrange(n):
for j in xrange(i + 1, n):
if self.matrix[i, j] == 1:
pyplot.plot((x[i], x[j]), (y[i], y[j]), color = 'blue')
pyplot.show()
but can be optimized.
You may be interested in the popular
networkx
project, if you're interested in simply reducing the amount of code you write.Disclaimer: I am a contributor to
networkx
.