本文整理汇总了Python中networkx.draw_networkx函数的典型用法代码示例。如果您正苦于以下问题:Python draw_networkx函数的具体用法?Python draw_networkx怎么用?Python draw_networkx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了draw_networkx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
def initialize():
G.add_node("A")
G.add_node("B")
G.add_node("C")
G.add_node("D")
G.add_node("E")
G.add_node("F")
labels = {k: k for k in G.nodes()}
G.add_edge("A", "F", weight=1)
G.add_edge("A", "E", weight=3)
G.add_edge("A", "C", weight=4)
G.add_edge("F", "B", weight=3)
G.add_edge("F", "E", weight=2)
G.add_edge("B", "D", weight=3)
G.add_edge("B", "E", weight=2)
G.add_edge("E", "D", weight=4)
G.add_edge("E", "C", weight=2)
G.add_edge("C", "D", weight=1)
labels = nx.get_edge_attributes(G, "weight")
plt.title("Single-Router Network")
nx.draw(G, pos=nx.spectral_layout(G))
nx.draw_networkx(G, with_labels=True, pos=nx.spectral_layout(G))
nx.draw_networkx_edge_labels(G, pos=nx.spectral_layout(G), edge_labels=labels)
plt.show()
示例2: reactionCenter
def reactionCenter(filename):
# in this method, g2 do not need to be subgraph of g1
mcs = fmcsWithPath(filename=filename)
# print(mcs['content1'])
# print(mcs['content2'])
# print(mcs['contentmcs'])
# g1 = input_chem_content(mcs['content1'], 'g1')
g1 = graphFromSDF(StringIO(mcs['content1']))[0]
print g1.node
# nx.draw_networkx(g1)
# pyplot.show( )
# g2 = input_chem_content( mcs['content2'], 'g2' )
g2 = graphFromSDF( StringIO( mcs['content2'] ) )[0]
print g2.node
# nx.draw_networkx( g2)
# pyplot.show( )
# gmcs = input_chem_content(mcs['contentmcs'], 'g2')
gmcs = graphFromSDF( StringIO( mcs['contentmcs'] ) )[0]
nx.draw_networkx(gmcs)
pyplot.show()
print getReactionCenter(g1, gmcs)
示例3: draw
def draw(inF):
G = nx.Graph()
inFile = open(inF)
S = set()
for line in inFile:
line = line.strip()
fields = line.split('\t')
for item in fields:
S.add(item)
inFile.close()
L = list(S)
G.add_nodes_from(L)
LC = []
for x in L:
if x == 'EGR1' or x == 'RBM20':
LC.append('r')
else:
LC.append('w')
inFile = open(inF)
for line in inFile:
line = line.strip()
fields = line.split('\t')
for i in range(len(fields)-1):
G.add_edge(fields[i], fields[i+1])
inFile.close()
nx.draw_networkx(G,pos=nx.spring_layout(G), node_size=800, font_size=6, node_color=LC)
limits=plt.axis('off')
plt.savefig(inF + '.pdf')
示例4: graph_show
def graph_show(graph, font_size=12):
pylab.rcParams['figure.figsize'] = (16.0, 12.0)
try:
nx.draw_networkx(graph,pos=nx.spring_layout(graph), node_size=6, alpha=0.1, font_size=font_size)
except:
print 'umm'
pylab.rcParams['figure.figsize'] = (10.0, 4.0)
示例5: draw_graph
def draw_graph(self, G, node_list=None, edge_colour='k', node_size=15, node_colour='r', graph_type='spring',
back_bone=None, side_chains=None, terminators=None):
# determine nodelist
if node_list is None:
node_list = G.nodes()
# determine labels
labels = {}
for l_atom in G.nodes_iter():
labels[l_atom] = l_atom.symbol
# draw graphs based on graph_type
if graph_type == 'circular':
nx.draw_circular(G, with_labels=True, labels=labels, node_list=node_list, node_size=node_size,
edge_color=edge_colour, node_color=node_colour)
elif graph_type == 'random':
nx.draw_random(G, with_labels=True, labels=labels, node_list=node_list, node_size=node_size,
edge_color=edge_colour, node_color=node_colour)
elif graph_type == 'spectral':
nx.draw_spectral(G, with_labels=True, labels=labels, node_list=node_list, node_size=node_size,
edge_color=edge_colour, node_color=node_colour)
elif graph_type == 'spring':
nx.draw_spring(G, with_labels=True, labels=labels, node_list=node_list, node_size=node_size,
edge_color=edge_colour, node_color=node_colour)
elif graph_type == 'shell':
nx.draw_shell(G, with_labels=True, labels=labels, node_list=node_list, node_size=node_size,
edge_color=edge_colour, node_color=node_colour)
# elif graph_type == 'protein':
# self.draw_protein(G, with_labels=True, labels=labels, node_list=node_list, node_size=node_size,
# edge_color=edge_colour, node_color=node_colour, back_bone, side_chains, terminators)
else:
nx.draw_networkx(G, with_labels=True, labels=labels, node_list=node_list, node_size=node_size,
edge_color=edge_colour, node_color=node_colour)
plt.show()
示例6: create_simple_graph
def create_simple_graph(self,name):
import networkx as nx
G=nx.Graph()
for i,r in enumerate(self.reslist):
G.add_node(i+1,name=r.name)
print G.nodes()
h = self.hbond_matrix()
nr = numpy.size(h,0)
for i in range(nr):
for j in range(i+1,nr):
if GenericResidue.touching(self.reslist[i], self.reslist[j],2.8):
print 'adding edge',i+1,j+1
G.add_edge(i+1,j+1,name="special")
# pos0=nx.spectral_layout(G)
# pos=nx.spring_layout(G,iterations=500,pos=pos0)
# pos=nx.spring_layout(G,iterations=500)
# nx.draw_shell(G)
pos0=nx.spectral_layout(G)
pos=nx.spring_layout(G,iterations=500,pos=pos0)
# pos=nx.graphviz_layout(G,root=1,prog='dot')
# nx.draw(G)
nx.draw_networkx(G,pos)
plt.axis('off')
plt.savefig(name)
示例7: observe
def observe():
global initialConditions
global g,estado,f,numNodos,numTipoNodos
estado=[]
contadorAgregado=[]
cla()
node_labels={}
cmapMio=creaCmap(4)
for i in g.nodes_iter():
node_labels[i]=g.node[i]['tipo']
nx.draw_networkx (g, k=0.8,node_color = [g.node[i]['tipo'] for i in g.nodes_iter()],
pos = g.pos,cmap=cmapMio, labels=node_labels)
for i in g.nodes_iter():
estado.append(g.node[i]['tipo'])
contador=collections.Counter(estado)
contadorAgregado=contador.values()
wr.writerow(contadorAgregado)
print contadorAgregado
if initialConditions == 0:
# Saving data used in simulation, using f of file defined in initialize()
f.write('GRID de ')
f.write(str(numNodos)+"\n y tipos de nodos: ")
f.write(str(numTipoNodos)+"\n")
f.write(str(contadorAgregado) +"\n")
f.write('Matrix'+"\n")
initialConditions=1
np.savetxt(f,betaMatrix, fmt='%.4e')
f.close()
开发者ID:falevian,项目名称:Bacterias-PrimerosPasos,代码行数:28,代码来源:00+Un+bacteria+contra+5+tres+estructura-grid-SinSimulador.py
示例8: draw_graph
def draw_graph(graph):
# extract nodes from graph
nodes = set([n1 for n1, n2 in graph] + [n2 for n1, n2 in graph])
# create networkx graph
G=nx.Graph()
#G=nx.cubical_graph()
# add nodes
for node in nodes:
G.add_node(node)
# add edges
for edge in graph:
G.add_edge(edge[0], edge[1])
# draw graph
#pos = nx.shell_layout(G)
#pos = nx.spectral_layout(G)
pos = nx.random_layout(G) # Funciona melhor
#pos = nx.circular_layout(G) # Mais ou menos
#pos = nx.fruchterman_reingold_layout(G) # Funciona melhor
#nx.draw(G, pos)
nx.draw_networkx(G)
# show graph
plt.axis('off')
plt.show()
示例9: draw_basic_network
def draw_basic_network(G,src_list):
slpos = nx.spring_layout(G) # see this for a great grid layout [1]
nx.draw_networkx(G, pos=slpos, node_color='b', nodelist=src_list, with_labels=False,node_size=20, \
edge_color='#7146CC')
nx.draw_networkx_nodes(G, pos=slpos, node_color='r', nodelist=[x for x in G.nodes() if x not in src_list], \
alpha=0.8, with_labels=False,node_size=20)
plt.savefig('figures/basicfig', bbox_inches='tight', pad_inches=0)
示例10: draw
def draw(self):
"""
Draw a network graph of the employee relationship.
"""
if self.graph is not None:
nx.draw_networkx(self.graph)
plt.show()
示例11: tree_width
def tree_width(nxg,i):
maxsize=1000000000
junction_tree=nx.Graph()
max_junction_tree_node=junction_tree
all_subgraphs=create_all_subgraphs(nxg.edges(),i)
print "All subgraphs:",all_subgraphs
print "============================================"
for k0 in all_subgraphs:
for k1 in all_subgraphs:
hash_graph_k0 = hash_graph(k0)
hash_graph_k1 = hash_graph(k1)
if (hash_graph_k0 != hash_graph_k1) and len(set(k0).intersection(set(k1))) > 0:
junction_tree.add_edge(hash_graph_k0,hash_graph_k1)
if len(k0) < maxsize:
max_junction_tree_node=k0
maxsize = len(k0)
if len(k1) < maxsize:
max_junction_tree_node=k1
maxsize = len(k1)
print "============================================"
print "Junction Tree (with subgraphs of size less than",i,") :"
nx.draw_networkx(junction_tree)
plt.show()
print "============================================"
print "Junction Tree Width for subgraphs of size less than ",i," - size of largest node set:",maxsize
示例12: create_networkx
def create_networkx(node_list, edge_list, args):
graph = nx.Graph()
print 'Initializing'
size_list = []
clean_node_list = []
for item in node_list:
nodesize = 300
for edge in edge_list:
if item == edge[1]:
nodesize += 100
size_list.append(nodesize)
clean_node_list.append(os.path.basename(item))
graph.add_nodes_from(clean_node_list)
print 'Nodes set'
for item in edge_list:
from_node = os.path.basename(item[1])
to_node = os.path.basename(item[0])
graph.add_edge(from_node, to_node)
print 'Edges set'
print 'Creating Graph'
position = nx.spring_layout(graph)
for item in position:
position[item] *= 10
nx.draw_networkx(graph,
pos=position,
font_size=10,
node_size=size_list)
print 'Drawing Graph'
plt.show()
print 'DONE'
示例13: plot_osm_network
def plot_osm_network(G,node_size=10,with_labels=False,ax=None):
plt.figure()
pos = {}
for n in G.nodes():
pos[n] = (G.node[n].lon, G.node[n].lat)
nx.draw_networkx(G,pos,node_size=node_size,with_labels=with_labels,ax=ax)
plt.show()
示例14: draw_geograph
def draw_geograph(g, node_color='r', edge_color='b', node_label_field=None,
edge_label_field=None, node_size=200, node_label_x_offset=0,
node_label_y_offset=0, node_label_font_size=12,
node_label_font_color='k'):
"""
Simple function to draw a geograph via matplotlib/networkx
Uses geograph coords (projects if needed) as node positions
"""
# transform to projected if not done so
flat_coords = g.transform_coords(gm.PROJ4_FLAT_EARTH)
node_pos = {nd: flat_coords[nd] for nd in g.nodes()}
label_pos = {nd: [flat_coords[nd][0] + node_label_x_offset,
flat_coords[nd][1] + node_label_y_offset]
for nd in g.nodes()}
# Draw nodes
nx.draw_networkx(g, pos=node_pos, node_color=node_color,
with_labels=False, edge_color=edge_color, node_size=node_size)
if node_label_field:
if node_label_field != 'ix':
label_vals = nx.get_node_attributes(g, node_label_field)
nx.draw_networkx_labels(g, label_pos, labels=label_vals,
font_size=node_label_font_size, font_color=node_label_font_color)
else: # label via ids
nx.draw_networkx_labels(g, label_pos, labels=g.nodes(),
font_size=node_label_font_size, font_color=node_label_font_color)
# handle edge labels if needed
if edge_label_field:
edge_labels = nx.get_edge_attributes(g, edge_label_field)
nx.draw_networkx_edge_labels(g, pos=node_pos, edge_labels=edge_labels)
示例15: drawgraph
def drawgraph(self,path,nodelist):
color = {}
graph = nx.Graph()
for item in nodelist:
graph.add_node(item.key.decode('utf-8'))
if item.key in path.split('->'):
color[item.key.decode('utf-8')] = 'green'
for item in nodelist:
if item.path == '':
continue
s = item.path.split('->')
for i in range(0,len(s) - 1):
if i == 0:
continue
graph.add_edge(s[i].decode('utf-8'),s[i+1].decode('utf-8'))
values = [color.get(node,'red') for node in graph.nodes() ]
pos = nx.spring_layout(graph)
if len(nodelist) > 500:
nx.draw_networkx(graph,font_family='SimHei', node_size=50,node_color=values, font_size = 5)
else:
nx.draw_networkx(graph,font_family='SimHei', node_size=1000,node_color=values, font_size = 10)
plt.savefig('HSearch.png')
plt.close()
return None