本文整理汇总了Python中networkx.shell_layout函数的典型用法代码示例。如果您正苦于以下问题:Python shell_layout函数的具体用法?Python shell_layout怎么用?Python shell_layout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shell_layout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scale_and_center_arg
def test_scale_and_center_arg(self):
G = nx.complete_graph(9)
G.add_node(9)
vpos = nx.random_layout(G, scale=2, center=(4,5))
self.check_scale_and_center(vpos, scale=2, center=(4,5))
vpos = nx.spring_layout(G, scale=2, center=(4,5))
self.check_scale_and_center(vpos, scale=2, center=(4,5))
vpos = nx.spectral_layout(G, scale=2, center=(4,5))
self.check_scale_and_center(vpos, scale=2, center=(4,5))
# circular can have twice as big length
vpos = nx.circular_layout(G, scale=2, center=(4,5))
self.check_scale_and_center(vpos, scale=2*2, center=(4,5))
vpos = nx.shell_layout(G, scale=2, center=(4,5))
self.check_scale_and_center(vpos, scale=2*2, center=(4,5))
# check default center and scale
vpos = nx.random_layout(G)
self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
vpos = nx.spring_layout(G)
self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
vpos = nx.spectral_layout(G)
self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
vpos = nx.circular_layout(G)
self.check_scale_and_center(vpos, scale=2, center=(0,0))
vpos = nx.shell_layout(G)
self.check_scale_and_center(vpos, scale=2, center=(0,0))
示例2: buildGraphFromTwitterFollowing
def buildGraphFromTwitterFollowing(self):
while True:
twitter_id=self.userq.get()
#print "======================================"
twitter_id_dict=json.loads(twitter_id.AsJsonString())
#print twitter_id_dict["name"]
#print i.AsJsonString()
#pprint.pprint(i.GetCreatedAt())
#pprint.pprint(i.GetGeo())
#pprint.pprint(i.GetLocation())
#pprint.pprint(i.GetText())
for f in self.api.GetFollowers(twitter_id):
try:
follower_id_dict=json.loads(f.AsJsonString())
#print follower_id_dict["name"]
self.tng.add_edge(twitter_id_dict["name"],follower_id_dict["name"])
self.userq.put(f)
self.no_of_vertices+=1
except:
pass
if self.no_of_vertices > 50:
break
print "======================================"
nx.shell_layout(self.tng)
nx.draw_networkx(self.tng)
print "==========================================================================================="
print "Bonacich Power Centrality of the Social Network (Twitter) Crawled - computed using PageRank"
print "(a degree centrality based on social prestige)"
print "==========================================================================================="
print sorted(nx.pagerank(self.tng).items(),key=operator.itemgetter(1),reverse=True)
print "==========================================================================================="
print "Eigen Vector Centrality"
print "==========================================================================================="
print nx.eigenvector_centrality(self.tng)
plt.show()
示例3: test_single_nodes
def test_single_nodes(self):
G = nx.path_graph(1)
vpos = nx.shell_layout(G)
assert(vpos[0].any() == False)
G = nx.path_graph(3)
vpos = nx.shell_layout(G, [[0], [1,2]])
assert(vpos[0].any() == False)
示例4: test_shell_layout
def test_shell_layout(self):
G = nx.complete_graph(9)
shells=[[0], [1,2,3,5], [4,6,7,8]]
vpos = nx.shell_layout(G, nlist=shells)
vpos = nx.shell_layout(G, nlist=shells, scale=2, center=(3,4))
shells=[[0,1,2,3,5], [4,6,7,8]]
vpos = nx.shell_layout(G, nlist=shells)
vpos = nx.shell_layout(G, nlist=shells, scale=2, center=(3,4))
示例5: test_empty_graph
def test_empty_graph(self):
G=nx.Graph()
vpos = nx.random_layout(G)
vpos = nx.circular_layout(G)
vpos = nx.spring_layout(G)
vpos = nx.fruchterman_reingold_layout(G)
vpos = nx.shell_layout(G)
vpos = nx.spectral_layout(G)
# center arg
vpos = nx.random_layout(G, scale=2, center=(4,5))
vpos = nx.circular_layout(G, scale=2, center=(4,5))
vpos = nx.spring_layout(G, scale=2, center=(4,5))
vpos = nx.shell_layout(G, scale=2, center=(4,5))
vpos = nx.spectral_layout(G, scale=2, center=(4,5))
示例6: test_single_node
def test_single_node(self):
G = nx.Graph()
G.add_node(0)
vpos = nx.random_layout(G)
vpos = nx.circular_layout(G)
vpos = nx.spring_layout(G)
vpos = nx.fruchterman_reingold_layout(G)
vpos = nx.shell_layout(G)
vpos = nx.spectral_layout(G)
# center arg
vpos = nx.random_layout(G, scale=2, center=(4,5))
vpos = nx.circular_layout(G, scale=2, center=(4,5))
vpos = nx.spring_layout(G, scale=2, center=(4,5))
vpos = nx.shell_layout(G, scale=2, center=(4,5))
vpos = nx.spectral_layout(G, scale=2, center=(4,5))
示例7: saveImage
def saveImage( self, nrepr = "spring", ft = "png", filename = "", graph = None ):
"""store an image representation of the network"""
if graph == None:
if self.Graph == None:
self._alert( "No network given, not drawing." )
return False
else:
graph = self.Graph
if self._output_dir == "":
self._extalert( "Target directory needs to be assigned with {!r} first!" )
return 1
if ft not in ( "png" ):
ft = "png"
if filename == "":
filename = self.ModelName + "." + ft
filename = os.path.join( self._output_dir, filename )
if nrepr == "shells":
shells = [ [ key for key in graph.nodes_iter( ) if graph.node[ key ][ "shell" ] == s ] for s in xrange( graph[ "shell" ] + 1 ) ]
pos = nx.shell_layout( graph, shells )
else:
pos = nx.spring_layout( graph )
plt.figure( figsize = ( 8, 8 ) )
nx.draw( graph, pos )
plt.savefig( filename )
示例8: draw_graph
def draw_graph(graph, labels=None, graph_layout='spring',
node_size=1600, node_color='blue', node_alpha=0.3,
node_text_size=12,
edge_color='blue', edge_alpha=0.3, edge_tickness=1,
edge_text_pos=0.3,
text_font='sans-serif'):
# create networkx graph
G=nx.Graph()
# add edges
for edge in graph:
G.add_edge(edge[0], edge[1])
# these are different layouts for the network you may try
if graph_layout == 'spring':
graph_pos=nx.spring_layout(G)
elif graph_layout == 'spectral':
graph_pos=nx.spectral_layout(G)
elif graph_layout == 'random':
graph_pos=nx.random_layout(G)
else:
graph_pos=nx.shell_layout(G)
# draw graph
nx.draw_networkx_nodes(G,graph_pos,node_size=node_size, alpha=node_alpha, node_color=node_color)
nx.draw_networkx_edges(G,graph_pos,width=edge_tickness, alpha=edge_alpha,edge_color=edge_color)
nx.draw_networkx_labels(G, graph_pos,font_size=node_text_size,font_family=text_font)
plt.show()
示例9: draw_graph
def draw_graph(G, labels=None, graph_layout='shell',
node_size=1600, node_color='blue', node_alpha=0.3,
node_text_size=12,
edge_color='blue', edge_alpha=0.3, edge_tickness=1,
edge_text_pos=0.3,
text_font='sans-serif'):
# these are different layouts for the network you may try
# shell seems to work best
if graph_layout == 'spring':
graph_pos=nx.spring_layout(G)
elif graph_layout == 'spectral':
graph_pos=nx.spectral_layout(G)
elif graph_layout == 'random':
graph_pos=nx.random_layout(G)
else:
graph_pos=nx.shell_layout(G)
# draw graph
nx.draw_networkx_nodes(G,graph_pos,node_size=node_size,
alpha=node_alpha, node_color=node_color)
nx.draw_networkx_edges(G,graph_pos,width=edge_tickness,
alpha=edge_alpha,edge_color=edge_color)
nx.draw_networkx_labels(G, graph_pos,font_size=node_text_size,
font_family=text_font)
nx.draw_networkx_edge_labels(G, graph_pos, edge_labels=labels,
label_pos=edge_text_pos)
# show graph
frame = plt.gca()
frame.axes.get_xaxis().set_visible(False)
frame.axes.get_yaxis().set_visible(False)
plt.show()
示例10: draw_graph
def draw_graph(graph, labels=None, graph_layout='shell',
node_size=120, node_color='blue', node_alpha=0.3,
node_text_size=8,
edge_color='blue', edge_alpha=0.3, edge_tickness=1,
edge_text_pos=0.3,
text_font='sans-serif'):
# create networkx graph
G=nx.Graph()
# add edges
for edge in graph:
G.add_edge(edge[0], edge[1])
print G.nodes()
nodeColors = []
nodeClients = []
for node in G.nodes():
if is_number(node):
nodeColors.append(0)
else:
nodeColors.append(1)
nodeClients.append(node)
edgeColors = []
for edge in G.edges():
if (edge[0] in nodeClients) or (edge[1] in nodeClients):
edgeColors.append(1)
else:
edgeColors.append(0)
# these are different layouts for the network you may try
# shell seems to work best
if graph_layout == 'spring':
graph_pos=nx.spring_layout(G)
elif graph_layout == 'spectral':
graph_pos=nx.spectral_layout(G)
elif graph_layout == 'random':
graph_pos=nx.random_layout(G)
else:
graph_pos=nx.shell_layout(G)
# draw graph
nx.draw_networkx_nodes(G,graph_pos,node_size=node_size,
alpha=node_alpha, node_color=nodeColors)
nx.draw_networkx_edges(G,graph_pos,width=edge_tickness,
alpha=edge_alpha,edge_color=edgeColors)
nx.draw_networkx_labels(G, graph_pos,font_size=node_text_size,
font_family=text_font, font_weight='normal', alpha=1.0)
# if labels is None:
# labels = range(len(graph))
# edge_labels = dict(zip(graph, labels))
# nx.draw_networkx_edge_labels(G, graph_pos, edge_labels=edge_labels,
# label_pos=edge_text_pos)
# show graph
plt.show()
示例11: draw_graph
def draw_graph(self, graph):
graph_layout = 'shell'
node_size = 800
node_color = 'blue'
node_alpha = 0.3
node_text_size = 12
edge_color = 'blue'
edge_alpha = 0.3
edge_tickness = 1.5
nxGraph = nx.Graph()
figure = Figure(figsize=(5, 4), dpi=100)
plot_area = figure.add_subplot(111)
for edge in graph:
nxGraph.add_edge(edge[0], edge[1])
graph_pos = nx.shell_layout(nxGraph)
nx.draw_networkx_nodes(nxGraph, graph_pos, ax = plot_area, node_size = node_size, alpha = node_alpha, node_color = node_color)
nx.draw_networkx_edges(nxGraph, graph_pos, ax = plot_area, width = edge_tickness, alpha = edge_alpha, edge_color = edge_color)
nx.draw_networkx_labels(nxGraph, graph_pos, ax = plot_area, font_size=node_text_size)
self.canvas = FigureCanvasTkAgg(figure, master=self.parent)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
示例12: draw_graph
def draw_graph(graph, labels=None, graph_layout='shell',
node_size=1600, node_color='blue', node_alpha=0.3,
node_text_size=12,
edge_color='blue', edge_alpha=0.3, edge_tickness=1,
edge_text_pos=0.3,
text_font='sans-serif'):
# create networkx graph
G=nx.Graph()
# add edges
for edge in graph:
G.add_edge(edge[0], edge[1])
# these are different layouts for the network you may try
# shell seems to work best
if graph_layout == 'spring':
graph_pos=nx.spring_layout(G)
elif graph_layout == 'spectral':
graph_pos=nx.spectral_layout(G)
elif graph_layout == 'random':
graph_pos=nx.random_layout(G)
else:
graph_pos=nx.shell_layout(G)
nx.draw(G)
#nx.draw_random(G)
#nx.draw_spectral(G)
# show graph
newFolder = graphPath
if not os.path.exists(newFolder):
os.makedirs(newFolder)
plt.savefig(newFolder+anchor+"Network.png")
示例13: 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()
# 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)
nx.draw(G, pos)
# show graph
plt.show()
示例14: draw_simple
def draw_simple(self,title,color):
""" draws a simple graph without levels for an overview """
self.clean_edge() # make the succ minimal
print(self.matrix)
G=nx.DiGraph() # define a digraph
for i in self.liste:
G.add_node(i.name) # add all sits to graph as nodes
for i in self.liste:
for j in i.succ:
G.add_edge(i.name,j.name)
print()
# fill the labels with default values
labels={}
for l in G.nodes():
labels[l]=str(l)
# pos=nx.spring_layout(G)
# pos=nx.spectral_layout(G)
# pos=nx.random_layout(G)
pos=nx.shell_layout(G)
if(color==True):
nx.draw_networkx_nodes(G,pos,node_color='g',node_size=800)
else:
nx.draw_networkx_nodes(G,pos,node_color='lightgray',node_size=800)
nx.draw_networkx_edges(G,pos)
nx.draw_networkx_labels(G,pos)
plt.title('SIMPLE: '+title)
plt.axis('on')
plt.show()
示例15: draw
def draw(self):
# node attrs
node_size=1600
# 1-hop, 2-hop etc
root_color = 'red'
node_tiers = ['blue','green','yellow']
node_color='blue'
node_alpha=0.3
node_text_size=12
# edge attrs
edge_color='black'
edge_alpha=0.3
edge_tickness=1
edge_text_pos=0.3
f = plt.figure()
graph_pos = nx.shell_layout(self.G)
# draw graph
nx.draw_networkx_nodes(self.G, graph_pos, nodelist=[self.root], alpha=node_alpha, node_color=root_color)
for hop, nodes in self.hops.iteritems():
if len(nodes) == 0: continue
print hop
nx.draw_networkx_nodes(self.G, graph_pos, nodelist=nodes,
alpha=node_alpha, node_color=node_tiers[hop-1])
nx.draw_networkx_edges(self.G,graph_pos, edgelist=self.hops_edges[hop],
width=edge_tickness, alpha=edge_alpha, edge_color=edge_color)
nx.draw_networkx_labels(self.G, graph_pos,font_size=node_text_size)