def create_image(g, path):
path = os.path.relpath(path)
if pygraphviz:
a = nx.nx_agraph.to_agraph(g)
# ['neato'|'dot'|'twopi'|'circo'|'fdp'|'nop']
a.layout(prog='neato', args="-Goverlap=false -Gsplines=true") # splines=true
a.draw(path)
elif plt:
nodes = g.nodes(True)
colors = [attrs['color'] for n, attrs in nodes]
labels = {n: attrs['label'] for n, attrs in nodes}
if graphviz_layout:
pos = graphviz_layout(g)
else:
pos = nx.spring_layout(g)
nx.draw_networkx_nodes(g, pos, node_shape='o', node_color=colors, alpha=0.3)
nx.draw_networkx_edges(g, pos, style='solid', alpha=0.2)
nx.draw_networkx_labels(g, pos, labels, alpha=0.5)
# plt.show()
plt.imsave(path) # todo: this is not tested!
print 'Image saved to', path
python类draw_networkx_edges()的实例源码
assignment_prob_hungarian.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 35
收藏 0
点赞 0
评论 0
def hungarian(B ,pos ,cost):
n = len(cost)
ret = 0;
max_match = 0
xy = [-1] * n
yx = [-1] * n
slack = [0] * n
slackx = [0] * n
lx, ly = init_labels(cost)
augment(cost, max_match, xy, yx, lx, ly, slack, slackx)
for x in range(n):
if (x, chr(xy[x]+97)) in B.edges():
nx.draw_networkx_edges(B, pos, edgelist = [(x, chr(xy[x]+97))], width = 2.5, alpha = 0.6, edge_color = 'r')
#takes input from the file and creates a weighted bipartite graph
bfs.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def BFS(G, source, pos):
visited = [False]*(len(G.nodes()))
queue = [] #a queue for BFS traversal
queue.append(source)
visited[source] = True
while queue:
curr_node = queue.pop(0)
for i in G[curr_node]: #iterates through all the possible vertices adjacent to the curr_node
if visited[i] == False:
queue.append(i)
visited[i] = True
# nx.draw_networkx_edges(G, pos, edgelist = [(curr_node,i)], width = 2.5, alpha = 0.6, edge_color = 'r')
return
#takes input from the file and creates a weighted graph
dfs_visual.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 32
收藏 0
点赞 0
评论 0
def DrawDFSPath(G, dfs_stk):
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels = True) #with_labels=true is to show the node number in the output graph
edge_labels = dict([((u,v,), d['length']) for u, v, d in G.edges(data = True)])
nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels, label_pos = 0.3, font_size = 11) #prints weight on all the edges
for i in dfs_stk:
#if there is more than one node in the dfs-forest, then print the corresponding edges
if len(i) > 1:
for j in i[ :(len(i)-1)]:
if i[i.index(j)+1] in G[j]:
nx.draw_networkx_edges(G, pos, edgelist = [(j,i[i.index(j)+1])], width = 2.5, alpha = 0.6, edge_color = 'r')
else:
#if in case the path was reversed because all the possible neighbours were visited, we need to find the adj node to it.
for k in i[1::-1]:
if k in G[j]:
nx.draw_networkx_edges(G, pos, edgelist = [(j,k)], width = 2.5, alpha = 0.6, edge_color = 'r')
break
#main function
def draw_transmat_graph_inner(G, edge_threshold=0, lw=1, ec='0.2', node_size=15):
num_states = G.number_of_nodes()
edgewidth = [ d['weight'] for (u,v,d) in G.edges(data=True)]
edgewidth = np.array(edgewidth)
edgewidth[edgewidth<edge_threshold] = 0
npos=circular_layout(G, scale=1, direction='CW')
nx.draw_networkx_edges(G, npos, alpha=1.0, width=edgewidth*lw, edge_color=ec)
nx.draw_networkx_nodes(G, npos, node_size=node_size, node_color='k',alpha=1.0)
ax = plt.gca()
ax.set_aspect('equal')
return ax
def draw_transmat_graph_outer(Go, Gi, edge_threshold=0, lw=1, ec='0.2', nc='k', node_size=15):
num_states = Go.number_of_nodes()
edgewidth = [ d['weight'] for (u,v,d) in Go.edges(data=True)]
edgewidth = np.array(edgewidth)
edgewidth[edgewidth<edge_threshold] = 0
npos=double_circular_layout(Gi, scale=1, direction='CW')
nx.draw_networkx_edges(Go, npos, alpha=1.0, width=edgewidth*lw, edge_color=ec)
nx.draw_networkx_nodes(Go, npos, node_size=node_size, node_color=nc,alpha=1.0)
ax = plt.gca()
ax.set_aspect('equal')
return ax
def save(self, path='out.png'):
import networkx
import matplotlib.pyplot as plt
pos = networkx.spring_layout(self.graph, iterations=500)
# pos = networkx.spectral_layout(self.graph)
# pos = networkx.shell_layout(self.graph)
# pos = networkx.fruchterman_reingold_layout(self.graph)
nodelist = list(range(self.num_rooms))
networkx.draw_networkx_nodes(self.graph, pos, nodelist=nodelist)
edgelist = sorted(self.edges - self.secret_edges)
secret = sorted(self.secret_edges)
networkx.draw_networkx_edges(self.graph, pos, edgelist=edgelist,
edge_color='k')
networkx.draw_networkx_edges(self.graph, pos, edgelist=secret,
edge_color='r')
networkx.draw_networkx_labels(self.graph, pos, self.labels)
plt.savefig(path)
def Drawsubgraph(HG, DrawGraph):
#Draw the graph
#print HG.nodes()
pos=nx.spring_layout(HG)
nx.draw_networkx_edges(HG, pos, alpha=0.4)
#nx.draw_networkx_labels(HG, pos, font_size=10, font_family='sans-serif')
i = 0
colorList = ['SeaGreen','yellow','brown','pink','purple','blue','green','Salmon','red','c','magenta','orange','white','black','y','skyblue','GreenYellow','cyan']#,'aqua'
for key in DrawGraph.keys():
nx.draw_networkx_nodes(HG, pos, nodelist=DrawGraph[key], node_size=20,node_color=colorList[i%len(colorList)])
i = i + 1
plt.title("Network Community Analysis")
plt.show()
###========================================================================================
def drawcomgraph(HG, DrawGraph):
#Draw the graph
#print HG.nodes()
pos=nx.spring_layout(HG)
nx.draw_networkx_edges(HG, pos, alpha=0.4)
nx.draw_networkx_labels(HG, pos, font_size=6, font_family='sans-serif')
i = 0
colorList = ['SeaGreen','yellow','brown','pink','purple','blue','green','Salmon','red','c','magenta','orange','white','black','y','skyblue','GreenYellow','cyan']#,'aqua'
for key in DrawGraph.keys():
nx.draw_networkx_nodes(HG, pos, nodelist=DrawGraph[key], node_size=100,node_color=colorList[i%len(colorList)])
i = i + 1
plt.title("Network Community Analysis")
plt.show()
#************************************************************************
def drawcomgraph(HG, DrawGraph):
#Draw the graph
#print HG.nodes()
pos=nx.spring_layout(HG)
nx.draw_networkx_edges(HG, pos, alpha=0.4)
nx.draw_networkx_labels(HG, pos, font_size=6, font_family='sans-serif')
i = 0
colorList = ['SeaGreen','yellow','brown','pink','purple','blue','green','Salmon','red','c','magenta','orange','white','black','y','skyblue','GreenYellow','cyan']#,'aqua'
for key in DrawGraph.keys():
nx.draw_networkx_nodes(HG, pos, nodelist=DrawGraph[key], node_size=100,node_color=colorList[i%len(colorList)])
i = i + 1
plt.title("Network Community Analysis")
plt.show()
#************************************************************************
def plot_networkx(self, with_label=False, block=True):
nx.draw_networkx_edges(
self.G, self.pos,
edge_color=self.edges_color(self.G.edges()),
alpha=0.08
)
if with_label:
nx.draw_networkx_labels(
self.G, self.pos,
font_size=8,
font_color='r',
alpha=0.2
)
nodes = self.G.nodes()
nx.draw_networkx_nodes(
self.G, self.pos,
node_size=self.nodes_size(nodes),
node_color=self.nodes_color(nodes),
alpha=0.85
)
plt.axis('off')
plt.show(block=block)
plt.clf()
def draw_graph(edges):
G = nx.DiGraph()
G.add_edges_from(edges)
values = [1.0 for node in G.nodes()]
# Specify the edges you want here
edge_colours = ['black' for edge in G.edges()]
black_edges = [edge for edge in G.edges()]
# Need to create a layout when doing
# separate calls to draw nodes and edges
pos = nx.spring_layout(G)
nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap('Reds'), node_color = values, node_size=4800)
nx.draw_networkx_edges(G, pos, edgelist=black_edges, arrows=True)
nx.draw_networkx_labels(G,pos,font_size=12,font_family='sans-serif')
plt.axis('off')
plt.show()
# In[183]:
def plotRoadsGraphNetworkx(G):
import matplotlib.pyplot as plt
eoriginal=[(u,v) for (u,v,d) in G.edges(data=True) if d['level'] >= 3]
enew=[(u,v) for (u,v,d) in G.edges(data=True) if d['level'] < 3]
pos={}
for n in G.nodes():
pos[n] = (G.node[n]['longitude'],G.node[n]['latitude'])
# nodes
nx.draw_networkx_nodes(G,pos,node_size=3)
# edges
nx.draw_networkx_edges(G,pos,edgelist=eoriginal,alpha=0.8,width=1)
nx.draw_networkx_edges(G,pos,edgelist=enew,width=1,alpha=0.8,edge_color='r')
# labels
nx.draw_networkx_labels(G,pos,font_size=20,font_family='sans-serif')
plt.show()
def drawRoads(G, edgeColorAttribute='level', edgeColorScale=9, nodeColorAttribute=None, nodeColorScale=None):
pos={}
for n in G.nodes():
pos[n] = (G.node[n]['longitude'],G.node[n]['latitude'])
# nodes
nx.draw_networkx_nodes(G,pos,node_size=0,alpha=0.8,color=colors[-1])
# edges
for i in range(0,9):
selectedEdges = [(u,v) for (u,v,d) in G.edges(data=True) if d['level'] == i]
selectedColors = [colors[i] for e in selectedEdges]
nx.draw_networkx_edges(G,pos,edgelist=selectedEdges,width=edgeWidth[i],edge_color=selectedColors)
plt.show()
def draw_tier2():
print 'loading tier2 data'
loadEntity(tier2filename)
print 'entity size: ', len(entityList)
G = nx.Graph()
G.add_node(u'???')
for entity in entityList:
name = entity.name[0].decode('utf8')
print name
G.add_node(name)
G.add_edge(u'???',name)
for child in entity.child:
cn = child.decode('utf8')
G.add_node(cn)
G.add_edge(name, cn)
pos=nx.spring_layout(G) # positions for all nodes
nx.draw_networkx_edges(G,pos,width=1.0,alpha=0.5)
# labels
nx.draw_networkx_labels(G,pos,font_size=15,font_family='sans-serif')
plt.axis('off')
plt.show()
# draw tier 3 test
def prepare_plot(graph):
"""
Prepares a Matplotlib plot for further handling
:param graph: datamodel.base.Graph instance
:return: None
"""
G = graph.nxgraph
# Color map for nodes: color is proportional to depth level
# http://matplotlib.org/examples/color/colormaps_reference.html
depth_levels_from_root = nx.shortest_path_length(G, graph.root_node)
vmax = 1.
colormap = plt.get_cmap('BuGn')
step = 1./len(graph)
node_colors = [vmax - step * depth_levels_from_root[n] for n in G.nodes()]
# Draw!
# https://networkx.github.io/documentation/networkx-1.10/reference/drawing.html
pos = nx.spectral_layout(G)
nx.draw_networkx_labels(G, pos,
labels=dict([(n, n.name) for n in G.nodes()]),
font_weight='bold',
font_color='orangered')
nx.draw_networkx_nodes(G, pos,
node_size=2000,
cmap=colormap,
vmin=0.,
vmax=vmax,
node_color=node_colors)
nx.draw_networkx_edge_labels(G, pos,
edge_labels=dict([((u, v,), d['name']) for u, v, d in G.edges(data=True)]))
nx.draw_networkx_edges(G, pos,
edgelist=[edge for edge in G.edges()],
arrows=True)
def plot2d(self, title=None, domain=[-1, 1], codomain=[-1, 1], predict=True):
f, ax = plt.subplots()
x1 = np.linspace(*domain, 100)
x2 = np.linspace(*codomain, 100)
n_samples, n_features = self.X_.shape
G = nx.from_scipy_sparse_matrix(self.A_)
pos = {i: self.X_[i] for i in range(n_samples)}
cm_sc = ListedColormap(['#AAAAAA', '#FF0000', '#0000FF'])
if title is not None:
ax.set_title(title)
ax.set_xlabel('$x_1$')
ax.set_ylabel('$x_2$')
ax.set_xlim(domain)
ax.set_ylim(codomain)
nx.draw_networkx_nodes(G, pos, ax=ax, node_size=25, node_color=self.y_, cmap=cm_sc)
if predict:
xx1, xx2 = np.meshgrid(x1, x2)
xfull = np.c_[xx1.ravel(), xx2.ravel()]
z = self.predict(xfull).reshape(100, 100)
levels = np.array([-1, 0, 1])
cm_cs = plt.cm.RdYlBu
if self.params['gamma_i'] != 0.0:
nx.draw_networkx_edges(G, pos, ax=ax, edge_color='#AAAAAA')
ax.contourf(xx1, xx2, z, levels, cmap=cm_cs, alpha=0.25)
return (f, ax)
def show_graph_communities(graph, partition, color_map=None, with_labels=False):
if color_map is None:
color_map = generate_color_map(partition)
pos = nx.spring_layout(graph,k=0.1,iterations=50)
comm_nodes = utils.partition_to_comm_nodes_map(partition)
for comm, nodes in comm_nodes.items():
nx.draw_networkx_nodes(graph, pos, nodelist=nodes, node_size=400,
node_color=color_map.get(comm), label=comm, cmap=plt.cm.jet)
if with_labels:
nx.draw_networkx_labels(graph, pos, font_size=12)
nx.draw_networkx_edges(graph, pos, alpha=0.3)
plt.legend()
plt.axis('off')
plt.show()
def show_graph(graph, with_labels=False):
pos = nx.spring_layout(graph)
nx.draw_networkx_nodes(graph, pos, node_size=200, node_color='red')
if with_labels:
nx.draw_networkx_labels(graph, pos, font_size=12)
nx.draw_networkx_edges(graph, pos, alpha=0.3)
plt.axis('off')
plt.show()
def draw_partition(graph, partition):
# requires matplotlib.pyplot, uncomment above
# uses community code and sample from http://perso.crans.org/aynaud/communities/ to draw matplotlib graph in shades of gray
g = graph
count = 0
size = float(len(set(partition.values())))
pos = nx.spring_layout(g)
for com in set(partition.values()):
count = count + 1
list_nodes = [nodes for nodes in partition.keys()
if partition[nodes] == com]
nx.draw_networkx_nodes(g, pos, list_nodes, node_size=20,
node_color=str(count / size))
nx.draw_networkx_edges(g, pos, alpha=0.5)
plt.show()
def ped_group(pedgraph, nlist, nscale=600, nalpha=0.95, nsize=15, ealpha=0.2, ewidth=0.3, ecolor="#000000",
atName="attr1", atCol=4):
'''
Receives a networkx graph and plots.
- needs matplotlib package
:param pedgraph: networkX graph object (pedigree)
:param nscale: scale of the plot
:param nalpha: node transparency
:param nsize: node size
:param ncolor: node color
:param ealpha: edge transparency
:param ewidth: edge width
:param ecolor: edge color
:return:
'''
grpList = [line.strip() for line in open(nlist, 'r')]
part = add_node_attribute("ped_testherd.in", pedgraph, atName=atName, atCol=atCol)
values = [part.get(node) for node in grpList]
pos = nx.spring_layout(pedgraph, scale=nscale)
nx.draw_networkx_nodes(pedgraph, pos, nodelist=grpList,
alpha=nalpha, node_color=values, node_size=nsize, linewidths=0.1,
cmap=plt.get_cmap('Paired'))
# label plot not feasable for larger networks
# nx.draw_networkx_labels(pedgraph, pos)
# nx.draw_networkx_edges(pedgraph, pos, alpha=ealpha, width=ewidth, edge_color=ecolor)
plt.axis("off")
plt.show()
a_star_search.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def aStarSearch(G, source, dest, heuristics, pos):
visited = {}
for node in G.nodes():
visited[node] = False
final_path = []
goal = aStarSearchUtil(G, source, visited, final_path, dest, 0)
prev = -1
for var in final_path:
if prev != -1:
curr = var
nx.draw_networkx_edges(G, pos, edgelist = [(prev,curr)], width = 2.5, alpha = 0.8, edge_color = 'black')
prev = curr
else:
prev = var
return
prims.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def prims(G, pos):
V = len(G.nodes()) # V denotes the number of vertices in G
dist = [] # dist[i] will hold the minimum weight edge value of node i to be included in MST
parent = [None]*V # parent[i] will hold the vertex connected to i, in the MST edge
mstSet = [] # mstSet[i] will hold true if vertex i is included in the MST
#initially, for every node, dist[] is set to maximum value and mstSet[] is set to False
for i in range(V):
dist.append(sys.maxsize)
mstSet.append(False)
dist[0] = 0
parent[0]= -1 #starting vertex is itself the root, and hence has no parent
for count in range(V-1):
u = minDistance(dist, mstSet, V) #pick the minimum distance vertex from the set of vertices
mstSet[u] = True
#update the vertices adjacent to the picked vertex
for v in range(V):
if (u, v) in G.edges():
if mstSet[v] == False and G[u][v]['length'] < dist[v]:
dist[v] = G[u][v]['length']
parent[v] = u
for X in range(V):
if parent[X] != -1: #ignore the parent of the starting node
if (parent[X], X) in G.edges():
nx.draw_networkx_edges(G, pos, edgelist = [(parent[X], X)], width = 2.5, alpha = 0.6, edge_color = 'r')
return
#takes input from the file and creates a weighted graph
egocentric_network_1_5.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def DrawGraph(G, egocentric_network_edge_list, egocentric_network_node_list, vert):
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels = True, node_color = 'blue', alpha = 0.8) #with_labels=true is to show the node number in the output graph
nx.draw_networkx_edges(G, pos, edgelist = egocentric_network_edge_list , width = 2.5, alpha = 0.8, edge_color = 'red')
nx.draw_networkx_nodes(G,pos, nodelist = egocentric_network_node_list, node_color = 'red', alpha = 0.5)
nx.draw_networkx_nodes(G,pos,nodelist=[vert],node_color='green',node_size=500,alpha=0.8)
return pos
egocentric_network_2.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def DrawGraph(G,egocentric_network_edge_list,egocentric_network_node_list):
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels = True, node_color = 'blue', alpha = 0.2) #with_labels=true is to show the node number in the output graph
nx.draw_networkx_edges(G, pos, edgelist = egocentric_network_edge_list , width = 2.5, alpha = 0.8, edge_color = 'blue')
nx.draw_networkx_nodes(G,pos, nodelist = egocentric_network_node_list, node_color = 'blue', alpha = 0.5)
return pos
egocentric_network_2.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def DrawGraph(G, egocentric_network_edge_list, egocentric_network_node_list, vert):
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels = True, node_color = 'blue', alpha = 0.8) #with_labels=true is to show the node number in the output graph
nx.draw_networkx_edges(G, pos, edgelist = egocentric_network_edge_list , width = 2.5, alpha = 0.8, edge_color = 'red')
nx.draw_networkx_nodes(G,pos, nodelist = egocentric_network_node_list, node_color = 'red', alpha = 0.5)
nx.draw_networkx_nodes(G,pos,nodelist=[vert],node_color='green',node_size=500,alpha=0.8)
return pos
egocentric_network_1.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def DrawGraph(G,egocentric_network_edge_list,egocentric_network_node_list, vert):
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels = True, node_color = 'blue', alpha = 0.8) #with_labels=true is to show the node number in the output graph
nx.draw_networkx_edges(G, pos, edgelist = egocentric_network_edge_list , width = 2.5, alpha = 0.8, edge_color = 'red')
nx.draw_networkx_nodes(G,pos, nodelist = egocentric_network_node_list, node_color = 'red', alpha = 0.5)
nx.draw_networkx_nodes(G,pos,nodelist=[vert],node_color='green',node_size=500,alpha=0.8)
return pos
kruskals_quick_union.py 文件源码
项目:Visualization-of-popular-algorithms-in-Python
作者: MUSoC
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def kruskals(G, pos):
eLen = len(G.edges()) # eLen denotes the number of edges in G
vLen = len(G.nodes()) # vLen denotes the number of vertices in G
mst = [] # mst contains the MST edges
mstFlag = {} # mstFlag[i] will hold true if the edge i has been processed for MST
for i in [ (u, v, edata['length']) for u, v, edata in G.edges(data = True) if 'length' in edata ]:
mstFlag[i] = False
parent = [None] * vLen # parent[i] will hold the vertex connected to i, in the MST
order = [None] * vLen # order[i] will hold the order of appearance of the node in the MST
for v in range(vLen):
parent[v] = v
order[v] = 0
while len(mst) < vLen - 1 :
curr_edge = getMin(G, mstFlag) # pick the smallest egde from the set of edges
mstFlag[curr_edge] = True # update the flag for the current edge
y = findRoot(parent, curr_edge[1])
x = findRoot(parent, curr_edge[0])
# adds the edge to MST, if including it doesn't form a cycle
if x != y:
mst.append(curr_edge)
union(parent, order, x, y)
# Else discard the edge
# marks the MST edges with red
for X in mst:
if (X[0], X[1]) in G.edges():
nx.draw_networkx_edges(G, pos, edgelist = [(X[0], X[1])], width = 2.5, alpha = 0.6, edge_color = 'r')
return
# takes input from the file and creates a weighted graph
def draw_transmat_graph(G, edge_threshold=0, lw=1, ec='0.2', node_size=15):
num_states = G.number_of_nodes()
edgewidth = [ d['weight'] for (u,v,d) in G.edges(data=True)]
edgewidth = np.array(edgewidth)
edgewidth[edgewidth<edge_threshold] = 0
labels = {}
labels[0] = '1'
labels[1]= '2'
labels[2]= '3'
labels[num_states-1] = str(num_states)
npos=circular_layout(G, scale=1, direction='CW')
lpos=circular_layout(G, scale=1.15, direction='CW')
nx.draw_networkx_edges(G, npos, alpha=0.8, width=edgewidth*lw, edge_color=ec)
nx.draw_networkx_nodes(G, npos, node_size=node_size, node_color='k',alpha=0.8)
ax = plt.gca()
nx.draw_networkx_labels(G, lpos, labels, fontsize=18, ax=ax); # fontsize does not seem to work :/
ax.set_aspect('equal')
return ax
def nx_plot(adj, pos, value):
# input: adjacent matrix, position, value map
label = np.arange(len(pos))
G=nx.from_numpy_matrix(adj)
nx.draw_networkx_nodes(G, pos, node_color = value)
nx.draw_networkx_labels(G, pos)
nx.draw_networkx_edges(G, pos)
plt.ion()
plt.show()