本文整理汇总了Python中networkx.draw_spectral函数的典型用法代码示例。如果您正苦于以下问题:Python draw_spectral函数的具体用法?Python draw_spectral怎么用?Python draw_spectral使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了draw_spectral函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_graph
def draw_graph(g, out_filename):
nx.draw(g)
nx.draw_random(g)
nx.draw_circular(g)
nx.draw_spectral(g)
plt.savefig(out_filename)
示例2: ministro_ministro
def ministro_ministro(G):
"""
Cria um grafo de ministros conectados de acordo com a sobreposição de seu uso da legislação
Construido a partir to grafo ministro_lei
"""
GM = nx.Graph()
for m in G:
try:
int(m)
except ValueError:# Add only if node is a minister
if m != "None":
GM.add_node(m.decode('utf-8'))
# Add edges
for n in GM:
for m in GM:
if n == m: continue
if GM.has_edge(n,m) or GM.has_edge(m,n): continue
# Edge weight is the cardinality of the intersection each node neighbor set.
w = len(set(nx.neighbors(G,n.encode('utf-8'))) & set(nx.neighbors(G,m.encode('utf-8')))) #encode again to allow for matches
if w > 5:
GM.add_edge(n,m,{'weight':w})
# abreviate node names
GMA = nx.Graph()
GMA.add_weighted_edges_from([(o.replace('MIN.','').strip(),d.replace('MIN.','').strip(),di['weight']) for o,d,di in GM.edges_iter(data=True)])
P.figure()
nx.draw_spectral(GMA)
nx.write_graphml(GMA,'ministro_ministro.graphml')
nx.write_gml(GMA,'ministro_ministro.gml')
nx.write_pajek(GMA,'ministro_ministro.pajek')
nx.write_dot(GMA,'ministro_ministro.dot')
return GMA
示例3: displayGraph
def displayGraph(self, g, label=False):
axon, sd = axon_dendrites(g)
sizes = node_sizes(g) * 50
if len(sizes) == 0:
print('Empty graph for cell. Make sure proto file has `*asymmetric` on top. I cannot handle symmetric compartmental connections')
return
weights = np.array([g.edge[e[0]][e[1]]['weight'] for e in g.edges()])
pos = nx.graphviz_layout(g, prog='twopi')
xmin, ymin, xmax, ymax = 1e9, 1e9, -1e9, -1e9
for p in list(pos.values()):
if xmin > p[0]:
xmin = p[0]
if xmax < p[0]:
xmax = p[0]
if ymin > p[1]:
ymin = p[1]
if ymax < p[1]:
ymax = p[1]
edge_widths = 10.0 * weights / max(weights)
node_colors = ['k' if x in axon else 'gray' for x in g.nodes()]
lw = [1 if n.endswith('comp_1') else 0 for n in g.nodes()]
self.axes.clear()
try:
nx.draw_graphviz(g, ax=self.axes, prog='twopi', node_color=node_colors, lw=lw)
except (NameError, AttributeError) as e:
nx.draw_spectral(g, ax=self.axes, node_color=node_colors, lw=lw, with_labels=False, )
示例4: draw_networkx_ex
def draw_networkx_ex():
G = nx.dodecahedral_graph()
nx.draw(G)
plt.show()
nx.draw_networkx(G, pos=nx.spring_layout(G))
limits = plt.axis('off')
plt.show()
nodes = nx.draw_networkx_nodes(G, pos=nx.spring_layout(G))
plt.show()
edges = nx.draw_networkx_edges(G, pos=nx.spring_layout(G))
plt.show()
labels = nx.draw_networkx_labels(G, pos=nx.spring_layout(G))
plt.show()
edge_labels = nx.draw_networkx_edge_labels(G, pos=nx.spring_layout(G))
plt.show()
print("Circular layout")
nx.draw_circular(G)
plt.show()
print("Random layout")
nx.draw_random(G)
plt.show()
print("Spectral layout")
nx.draw_spectral(G)
plt.show()
print("Spring layout")
nx.draw_spring(G)
plt.show()
print("Shell layout")
nx.draw_shell(G)
plt.show()
print("Graphviz")
示例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: tweet_flow
def tweet_flow():
global graph
print "Incoming Tweets!"
hashtag_edges = []
hastag_edges = get_edges_from_pairs(genereate_tags())
graph = max(nx.connected_component_subgraphs(graph), key=len)
for i in hastag_edges:
if i[0] != i[1] and len(i[0]) > len(i[1]):
graph.add_edge(i[0],i[1])
calc_average_degree()
nx.draw_spectral(graph,
node_size = 300,
width = 100,
node_color = '#A0CBE2', #light blue
edge_color = '#4169E1', #royal blue
font_size = 10,
with_labels = True )
plt.draw()
plt.pause(0.001)
time.sleep(60)
graph.clear()
tweet_flow()
示例7: draw_spectral_communities
def draw_spectral_communities(self):
partition = self.find_partition()[1]
node_color=[float(partition[v]) for v in partition]
labels = self.compute_labels()
nx.draw_spectral(self.G,node_color=node_color, labels=labels)
plt.show()
plt.savefig("C:\\Users\\Heschoon\\Dropbox\\ULB\\Current trends of artificial intelligence\\Trends_project\\graphs\\graph_spectral.pdf")
示例8: visualisation
def visualisation(chain, pairs):
G = nx.Graph()
a = range(len(chain))
G.add_edges_from([(i, i + 1) for i in a[:-1]])
G.add_edges_from(pairs)
nx.draw_spectral(G)
plt.show()
示例9: demo_save_fig
def demo_save_fig():
"""demo_save_fig"""
g = nx.Graph()
g.add_edges_from([(1, 2), (1, 3)])
g.add_node('sparm')
nx.draw(g)
nx.draw_random(g)
nx.draw_circular(g)
nx.draw_spectral(g)
plt.savefig("g.png")
示例10: drawGraph
def drawGraph():
time.sleep(15)
log.info("Network's topology graph:")
nx.draw_spectral(g)
nx.draw_networkx_edge_labels(g,pos=nx.spectral_layout(g))
#nx.draw_circular(g)
#nx.draw_networkx_edge_labels(g,pos=nx.circular_layout(g))
#nx.draw_shell(g)
#nx.draw_networkx_edge_labels(g,pos=nx.shell_layout(g))
plt.show()
示例11: main
def main():
print("Graphing!")
G = nx.Graph()
G.add_nodes_from([1-3])
G.add_edge(1, 2)
nx.draw_random(G)
nx.draw_circular(G)
nx.draw_spectral(G)
plt.show()
示例12: test_draw
def test_draw(self):
# hold(False)
N=self.G
nx.draw_spring(N)
pylab.savefig("test.png")
nx.draw_random(N)
pylab.savefig("test.ps")
nx.draw_circular(N)
pylab.savefig("test.png")
nx.draw_spectral(N)
pylab.savefig("test.png")
示例13: demo_write_doc
def demo_write_doc():
"""demo_write_doc"""
g = nx.Graph()
g.add_edges_from([(1, 2), (1, 3)])
g.add_node('sparm')
nx.draw(g)
nx.draw_random(g)
nx.draw_circular(g)
nx.draw_spectral(g)
nx.draw_graphviz(g)
nx.write_dot(g, 'g.dot')
示例14: drawGraph
def drawGraph():
time.sleep(15)
log.info("Network's topology graph:")
log.info(' -> ingress switches: {}'.format(list(ingress)))
log.info(' -> egress switches: {}'.format(list(egress)))
nx.draw_spectral(graph)
nx.draw_networkx_edge_labels(graph, pos=nx.spectral_layout(graph))
#nx.draw_circular(graph)
#nx.draw_networkx_edge_labels(graph, pos=nx.circular_layout(graph))
#nx.draw_shell(graph)
#nx.draw_networkx_edge_labels(graph, pos=nx.shell_layout(graph))
plt.show()
示例15: displayGraph
def displayGraph(self, g, label=False):
axon, sd = axon_dendrites(g)
sizes = node_sizes(g) * 50
if len(sizes) == 0:
print('Empty graph for cell. Make sure proto file has `*asymmetric` on top. I cannot handle symmetric compartmental connections')
return
node_colors = ['k' if x in axon else 'gray' for x in g.nodes()]
lw = [1 if n.endswith('comp_1') else 0 for n in g.nodes()]
self.axes.clear()
try:
nx.draw_graphviz(g, ax=self.axes, prog='twopi', node_color=node_colors, lw=lw)
except (NameError, AttributeError) as e:
nx.draw_spectral(g, ax=self.axes, node_color=node_colors, lw=lw, with_labels=False, )