本文整理汇总了Python中networkx.fruchterman_reingold_layout函数的典型用法代码示例。如果您正苦于以下问题:Python fruchterman_reingold_layout函数的具体用法?Python fruchterman_reingold_layout怎么用?Python fruchterman_reingold_layout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fruchterman_reingold_layout函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_fixed_node_fruchterman_reingold
def test_fixed_node_fruchterman_reingold(self):
# Dense version (numpy based)
pos = nx.circular_layout(self.Gi)
npos = nx.fruchterman_reingold_layout(self.Gi, pos=pos, fixed=[(0, 0)])
assert_equal(tuple(pos[(0, 0)]), tuple(npos[(0, 0)]))
# Sparse version (scipy based)
pos = nx.circular_layout(self.bigG)
npos = nx.fruchterman_reingold_layout(self.bigG, pos=pos, fixed=[(0, 0)])
for axis in range(2):
assert_almost_equal(pos[(0,0)][axis], npos[(0,0)][axis])
开发者ID:jklaise,项目名称:networkx,代码行数:10,代码来源:test_layout.py
示例2: test_smoke_int
def test_smoke_int(self):
G = self.Gi
vpos = nx.random_layout(G)
vpos = nx.circular_layout(G)
vpos = nx.spring_layout(G)
vpos = nx.fruchterman_reingold_layout(G)
vpos = nx.fruchterman_reingold_layout(self.bigG)
vpos = nx.spectral_layout(G)
vpos = nx.spectral_layout(self.bigG)
vpos = nx.shell_layout(G)
if self.scipy is not None:
vpos = nx.kamada_kawai_layout(G)
开发者ID:jklaise,项目名称:networkx,代码行数:12,代码来源:test_layout.py
示例3: user_neighborhood
def user_neighborhood(user_name, d1=20, d2=7):
import networkx
if user_name not in all_users:
return '%s is not in the list of users, please choose a different user or repo' % user_name
try:
watched_repos = list(user_sf[user_sf['user_name'] == user_name]['repos'][0])
edges = graph.get_edges(src_ids=watched_repos[:d1])
second_degree = edges.groupby('__src_id', {'dst': gl.aggregate.CONCAT('__dst_id')})
def flatten_edges(x):
return [[x['__src_id'], edge] for edge in x['dst'][:d2]]
edges = second_degree.flat_map(['__src_id','__dst_id'], lambda x: flatten_edges(x))
edges = list(edges.filter_by(list(watched_repos), '__dst_id', exclude=True))
G = networkx.Graph()
G.add_edges_from([[i['__src_id'], i['__dst_id']] for i in edges])
G.add_edges_from([[user_name , i['__src_id']] for i in edges])
pos=networkx.fruchterman_reingold_layout(G)
verts = list(graph.get_vertices(G.nodes()))
verts.append({'__id': user_name})
for vert in verts:
vert['x'] = int(pos.get(vert['__id'])[0]*10000)
vert['y'] = int(pos.get(vert['__id'])[1]*10000)
return {"edges": edges, "verts": verts}
except Exception as e:
return 'Exception error: %s' %type(e)
开发者ID:kaiyuzhao,项目名称:d3-react,代码行数:33,代码来源:repo_sim.py
示例4: build_neigh
def build_neigh(query_repo, k=50):
import networkx
if query_repo not in all_repos:
return '%s is not in the list of repos, please choose a public repo with at least 10 stargazers' % query_repo
result = None
try:
result = graph.get_neighborhood(query_repo, radius=2,)
verts, edges = result.get_vertices(), result.get_edges()
similar_text = rec_text.get_similar_items([query_repo], k)
text_search = verts.filter_by(similar_text['similar'], '__id')
text_search = list(set(text_search['__id']))
verts, edges = list(verts) , list(edges)
G = networkx.Graph()
G.add_edges_from([[i['__src_id'], i['__dst_id']] for i in edges])
pos=networkx.fruchterman_reingold_layout(G)
for vert in verts:
vert['x'] = int(pos.get(vert['__id'])[0]*10000)
vert['y'] = int(pos.get(vert['__id'])[1]*10000)
vert['text'] = 1 if vert['__id'] in text_search else 0
# vert['contributros'] = 1 if vert['__id'] in contributors else 0
return {"edges": edges, "verts": verts, "query": query_repo}
except Exception as e:
return 'Exception error: %s' %type(e)
开发者ID:kaiyuzhao,项目名称:d3-react,代码行数:30,代码来源:repo_sim.py
示例5: get_results
def get_results(self, images_dir):
"""Gathers the results of the CPM algorithm.
It gathers the results, images, and optimum solution as founded by the
CPM algorithm that run on the given project.
Args:
images_dir: a string, that represents the path that the images will be stored
Returns:
A tuple of three objects. The first object is a list of dictionaries,
the second object is a list of strings, and the third object is a tuple
of two numbers.
"""
pos = None
images = []
results = []
solutions = []
for iteration, snapshot in enumerate(self.snapshots):
graph = pickle.loads(snapshot)
results.append(graph.results)
solutions.append((graph.results['total_cost'], graph.results['project_duration']))
if iteration == 0:
pos = networkx.fruchterman_reingold_layout(graph)
images.append(draw_network(graph, pos, images_dir, iteration))
optimum_solution = min(solutions)
return results, images, optimum_solution
开发者ID:ato1981,项目名称:cpm,代码行数:27,代码来源:cpm.py
示例6: test_smoke_string
def test_smoke_string(self):
G=self.Gs
vpos=nx.random_layout(G)
vpos=nx.circular_layout(G)
vpos=nx.spring_layout(G)
vpos=nx.fruchterman_reingold_layout(G)
vpos=nx.spectral_layout(G)
vpos=nx.shell_layout(G)
开发者ID:JaneliaSciComp,项目名称:Neuroptikon,代码行数:8,代码来源:test_layout.py
示例7: plot_graph
def plot_graph(graph):
plt.figure(figsize=(20,12))
pos = nx.fruchterman_reingold_layout(graph)
nx.draw_networkx_nodes(graph, pos, node_size=70)
nx.draw_networkx_edges(graph, pos, edgelist=[(u,v) for (u,v,d) in graph.edges(data=True)], width=0.25, edge_color="m", alpha=0.3)
nx.draw_networkx_labels(graph, pos, font_size=7, font_family='sans-serif', font_color="b", alpha=0.2)
plt.axis('off')
plt.show()
开发者ID:danielgeng,项目名称:cs249_data_science,代码行数:8,代码来源:script.py
示例8: plot_optimal
def plot_optimal():
plt.figure(2)
individual = self.__best_individual__()
G = nx.Graph()
G.add_nodes_from(individual.names)
some_edges = [tuple(list(x)) for x in individual.edges]
G.add_edges_from(some_edges)
layout = nx.fruchterman_reingold_layout(G)
nx.draw_networkx(G, pos=layout, cmap=plt.get_cmap('jet'), node_color=individual.colors.values())
开发者ID:henryzord,项目名称:TreeMIMIC,代码行数:9,代码来源:TreeMIMIC.py
示例9: test_smoke_empty_graph
def test_smoke_empty_graph(self):
G = []
vpos = nx.random_layout(G)
vpos = nx.circular_layout(G)
vpos = nx.spring_layout(G)
vpos = nx.fruchterman_reingold_layout(G)
vpos = nx.spectral_layout(G)
vpos = nx.shell_layout(G)
if self.scipy is not None:
vpos = nx.kamada_kawai_layout(G)
开发者ID:ProgVal,项目名称:networkx,代码行数:10,代码来源:test_layout.py
示例10: make_graph
def make_graph(list_of_edges):
G = nx.Graph()
for x in list_of_edges:
pair = tuple(x.split("-", 1))
G.add_edge(pair[0], pair[1])
print len(G.edges())
pos=nx.fruchterman_reingold_layout(G)
nx.draw(G,pos)
plt.show()
return len(list_of_edges)
开发者ID:BBischof,项目名称:visa_free,代码行数:10,代码来源:data_parser.py
示例11: test_spring_init_pos
def test_spring_init_pos(self):
# Tests GH #2448
import math
G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 0), (2, 3)])
init_pos = {0: (0.0, 0.0)}
fixed_pos = [0]
pos = nx.fruchterman_reingold_layout(G, pos=init_pos, fixed=fixed_pos)
has_nan = any(math.isnan(c) for coords in pos.values() for c in coords)
assert_false(has_nan, 'values should not be nan')
开发者ID:kalyi,项目名称:networkx,代码行数:11,代码来源:test_layout.py
示例12: test_center_parameter
def test_center_parameter(self):
G = nx.path_graph(1)
vpos = nx.random_layout(G, center=(1, 1))
vpos = nx.circular_layout(G, center=(1, 1))
assert_equal(tuple(vpos[0]), (1, 1))
vpos = nx.spring_layout(G, center=(1, 1))
assert_equal(tuple(vpos[0]), (1, 1))
vpos = nx.fruchterman_reingold_layout(G, center=(1, 1))
assert_equal(tuple(vpos[0]), (1, 1))
vpos = nx.spectral_layout(G, center=(1, 1))
assert_equal(tuple(vpos[0]), (1, 1))
vpos = nx.shell_layout(G, center=(1, 1))
assert_equal(tuple(vpos[0]), (1, 1))
开发者ID:jklaise,项目名称:networkx,代码行数:13,代码来源:test_layout.py
示例13: 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))
开发者ID:JFriel,项目名称:honours_project,代码行数:14,代码来源:test_layout.py
示例14: test_empty_graph
def test_empty_graph(self):
G = nx.empty_graph()
vpos = nx.random_layout(G, center=(1, 1))
assert_equal(vpos, {})
vpos = nx.circular_layout(G, center=(1, 1))
assert_equal(vpos, {})
vpos = nx.spring_layout(G, center=(1, 1))
assert_equal(vpos, {})
vpos = nx.fruchterman_reingold_layout(G, center=(1, 1))
assert_equal(vpos, {})
vpos = nx.spectral_layout(G, center=(1, 1))
assert_equal(vpos, {})
vpos = nx.shell_layout(G, center=(1, 1))
assert_equal(vpos, {})
开发者ID:jklaise,项目名称:networkx,代码行数:14,代码来源:test_layout.py
示例15: 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))
开发者ID:JFriel,项目名称:honours_project,代码行数:15,代码来源:test_layout.py
示例16: draw_streets_as_vertices
def draw_streets_as_vertices(g,ebc,max_ebc,save_img=False,save_name="saida.png"):
node_colors = []
nodes_to_label = {n:"" for n in g.nodes()}
for n in g.nodes():
node_colors.append( -ebc[n]/(1.0*max_ebc) )
if ebc[n]>=(max_ebc*0.4):
print n
nodes_to_label.update({n:n})
nx.draw_networkx(g,pos=nx.fruchterman_reingold_layout(g),font_size=12,with_labels=True,labels=nodes_to_label,linewidths=None,node_size=30,arrows=False,node_color=node_colors,cmap=plt.cm.RdYlGn, vmin=-1.0, vmax=0.0)
if save_img:
plt.savefig("%s/%s" % (mg.NODE_BETWEENNESS_IMG_FOLDER,save_name),dpi=1200)
else:
plt.show()
开发者ID:danoan,项目名称:traffic-simulator,代码行数:15,代码来源:map_draw.py
示例17: plot_graph
def plot_graph(graph, threshold, plotfolder):
idno = graph.graph["idno"]
# Filter the full graph by edge weight
graph = nx.Graph([(u, v, d) for u, v, d in graph.edges(data=True) if d['weight'] > threshold])
# Derive necessary data
weights = get_weights(graph)
edgelabels = create_edgelabels(graph)
positions = nx.fruchterman_reingold_layout(graph, k=2, scale=2)
# Perform the actual drawing
nx.draw_networkx_nodes(graph, positions, node_size=1200, node_color="g", label="label")
nx.draw_networkx_edges(graph, positions, width=weights)
nx.draw_networkx_labels(graph, positions, font_size=10)
nx.draw_networkx_edge_labels(graph, positions, edge_labels=edgelabels, font_size=8)
# Save the figure
plt.axis('off')
plt.title(str(idno))
plt.savefig(plotfolder + idno + "-plot.png", dpi=300)
plt.close()
开发者ID:cligs,项目名称:toolbox,代码行数:18,代码来源:pylina.py
示例18: draw_graph
def draw_graph(graph):
nodes = set([n1 for n1, n2, n3 in graph] + [n2 for n1, n2,n3 in graph])
G = nx.Graph()
for node in nodes:
G.add_node(node)
for edge in graph:
G.add_edge(edge[0], edge[1], weight = edge[2])
pos = nx.fruchterman_reingold_layout(G)
nx.draw(G, pos, node_size = 2)
edge_labels=dict([((u,v,),d['weight'])
for u,v,d in G.edges(data=True)])
nx.draw_networkx_edge_labels(G,pos,edge_labels=edge_labels)
# show graph
plt.show()
开发者ID:ppvoyage,项目名称:plotUtil_python,代码行数:18,代码来源:plot.py
示例19: weighted_edges
def weighted_edges(weight_tuples, table_type, table="following", categories = categories, colors = cat_colors, e_colors = edge_colors, l_colors = label_colors, fname = "following", users_table = "users"):
fname = fname+ ".dot"
G=nx.MultiDiGraph()
el = {}
for x in categories:
G.add_node( x , label = x + " ["+ str(users_count(x, users_table)) + "]", style='filled' , fillcolor=colors[x])
max_weight = max(weight_tuples,key=lambda item:item[2])[2]
summ = 0
for w in weight_tuples:
weight = w[2]
summ +=int(weight)
edge_weight = 9.0*weight/max_weight + 1
'''
if weight > 1000:
edge_weight = 10
elif weight > 100:
edge_weight = 7
elif weight > 50:
edge_weight = 3
'''
G.add_edge(w[0], w[1], label=str(weight), fontcolor = l_colors[w[0]], style="bold", color= e_colors[w[0]], fontsize=13, fontweight=10, penwidth=edge_weight)
el[(w[0], w[1])] = int(weight)
pos = nx.circular_layout(G) # positions for all nodes
pos = nx.spectral_layout(G)
pos = nx.shell_layout(G)
pos = nx.fruchterman_reingold_layout(G)
#pos = nx.circular_layout(G)
# nodes
nx.draw_networkx_nodes(G,pos,node_list=categories)
nx.draw_networkx_labels(G,pos,font_size=7,font_family='sans-serif')
# edges
nx.draw_networkx_edges(G,pos)
nx.draw_networkx_edge_labels(G,pos, edge_labels = el,)
#plt.axis('off')
#plt.savefig("edges.png")
nx.write_dot(G,fname)
print "done :D "
print "dot file in " + fname +" :D :D :D"
开发者ID:koprty,项目名称:REU_scripts,代码行数:41,代码来源:weighted_network_fiddlings.py
示例20: draw_graph
def draw_graph(graph):
nodedata = [(v["weight"], {n: v["label"]}) for (n, v) in graph.nodes(data=True)]
nodelabels = {}
nodeweights = []
for weight, label in nodedata:
nodeweights.append(weight)
nodelabels.update(label)
# maxweight = max(nodeweights)
# minweight = min(nodeweights)
# ratio = maxweight/minweight
# nodeweights = map(lambda x: x/ratio, nodeweights)
# pos = nx.random_layout(graph)
pos = nx.fruchterman_reingold_layout(graph)
nx.draw_networkx_nodes(graph, pos, node_size=nodeweights, node_color="w", alpha=0.4)
nx.draw_networkx_labels(graph, pos, nodelabels)
nx.draw_networkx_edges(graph, pos)
output = basename(getcwd()) + ".gml"
if isfile(output):
remove(output)
nx.write_gml(graph, output)
plt.show() # display
开发者ID:sardok,项目名称:source-visualize,代码行数:21,代码来源:src2vis.py
注:本文中的networkx.fruchterman_reingold_layout函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论