Python converting ndarrays into graph -


so i'm working on python program, computes displacement of nodes in given undirected graph via algorithm. output consists of adjacency matrix in form of numpy ndarray , numpy ndarray holding coordinates(2d) of each node.

ive been looking ways of plotting resulting graph , stumbled across igraph , networkx. did not use them yet, know can convert adjacency matrix graph, in case not using coordinates though. wonder, how can use both graphical representation of graph?

i imagine have use both arrays create different kind of object, can converted networkx/igraph.

networkx solution:

the draw nx.function: takes in optional second argument of positions:

import numpy np import networkx nx import pylab plt  = np.array([[0,0,1,0],[1,0,0,0],[1,0,0,1],[1,0,0,0]]) g = nx.digraph(a)  pos = [[0,0], [0,1], [1,0], [1,1]] nx.draw(g,pos) plt.show() 

enter image description here


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -