当前位置: 首页>>代码示例>>Python>>正文


Python networkx.fruchterman_reingold_layout函数代码示例

本文整理汇总了Python中networkx.fruchterman_reingold_layout函数的典型用法代码示例。如果您正苦于以下问题:Python fruchterman_reingold_layout函数的具体用法?Python fruchterman_reingold_layout怎么用?Python fruchterman_reingold_layout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fruchterman_reingold_layout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的networkx.fruchterman_reingold_layout函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。