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


Python networkx.write_gexf方法代码示例

本文整理汇总了Python中networkx.write_gexf方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.write_gexf方法的具体用法?Python networkx.write_gexf怎么用?Python networkx.write_gexf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.write_gexf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def write_graph(self, G=None, subgraph_file=None):
        if G is None:
            G = self.context_graph
        if subgraph_file is None:
            subgraph_file = self.context_graph_file
        logging.info("Writing graph.")
        # write the graph out
        file_format = subgraph_file.split(".")[-1]
        if file_format == "graphml":
            nx.write_graphml(G, subgraph_file)
        elif file_format == "gml":
            nx.write_gml(G, subgraph_file)
        elif file_format == "gexf":
            nx.write_gexf(G, subgraph_file)
        elif file_format == "net":
            nx.write_pajek(G, subgraph_file)
        elif file_format == "yaml":
            nx.write_yaml(G, subgraph_file)
        elif file_format == "gpickle":
            nx.write_gpickle(G, subgraph_file)
        else:
            print "File format not found, writing graphml."
            nx.write_graphml(G, subgraph_file) 
开发者ID:vz-risk,项目名称:Verum,代码行数:25,代码来源:networkx.py

示例2: save

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def save(self, name, resolution, gain, equalize=True, cluster='agglomerative', statistics='db', max_K=5):
        """
        Generates a topological representation using the Mapper algorithm with resolution and gain specified by the
        parameters 'resolution' and 'gain'. When equalize is set to True, patches are chosen such that they
        contain the same number of points. The parameter 'cluster' specifies the clustering method ('agglomerative' or
        'kmeans'). The parameter 'statistics' specifies the criterion for choosing the optimal number of clusters
        ('db' for Davies-Bouildin index, or 'gap' for the gap statistic). The parameter 'max_K' specifies the maximum
        number of clusters to be considered within each patch. The topological representation is stored in the files
        'name.gexf' and 'name.json'. It returns a dictionary with the patches.
        """
        G, all_clusters, patches = sakmapper.mapper_graph(self.df, lens_data=self.lens_data_mds,
                                                          resolution=resolution,
                                                          gain=gain, equalize=equalize, clust=cluster,
                                                          stat=statistics, max_K=max_K)
        dic = {}
        for n, rs in enumerate(all_clusters):
            dic[str(n)] = map(lambda x: int(x), rs)
        with open(name + '.json', 'wb') as handle3:
            json.dump(dic, handle3)
        networkx.write_gexf(G, name + '.gexf')
        return patches 
开发者ID:CamaraLab,项目名称:scTDA,代码行数:23,代码来源:main.py

示例3: WriteAdjList

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def WriteAdjList(adjList, graphName, colorLabels=None):
    g = nx.Graph()

    for i in range(0,len(adjList)):
        if (colorLabels is not None):
            g.add_node(i, color=colorLabels[i], id=str(i))
        else:
            g.add_node(i)

    idx = 0
    for i in range(0,len(adjList)):
        for j in range(0,len(adjList[i])):
            g.add_edge(i, adjList[i][j][0], capacity=adjList[i][j][1])

    if (graphName.find("gml") >= 0):
        nx.write_gml(g, graphName)
    elif (graphName.find("gexf") >= 0):
        nx.write_gexf(g, graphName)
    elif (graphName.find("graphml") >= 0):
        nx.write_graphml(g, graphName) 
开发者ID:mrvollger,项目名称:SDA,代码行数:22,代码来源:ABPUtils.py

示例4: test_default_attribute

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def test_default_attribute(self):
        G=nx.Graph()
        G.add_node(1,label='1',color='green')
        G.add_path([0,1,2,3])
        G.add_edge(1,2,foo=3)
        G.graph['node_default']={'color':'yellow'}
        G.graph['edge_default']={'foo':7}
        fh = io.BytesIO()
        nx.write_gexf(G,fh)
        fh.seek(0)
        H=nx.read_gexf(fh,node_type=int)
        assert_equal(sorted(G.nodes()),sorted(H.nodes()))
        assert_equal(
            sorted(sorted(e) for e in G.edges()),
            sorted(sorted(e) for e in H.edges()))
        # Reading a gexf graph always sets mode attribute to either
        # 'static' or 'dynamic'. Remove the mode attribute from the
        # read graph for the sake of comparing remaining attributes.
        del H.graph['mode']
        assert_equal(G.graph,H.graph) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:22,代码来源:test_gexf.py

示例5: test_default_attribute

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def test_default_attribute(self):
        G = nx.Graph()
        G.add_node(1, label='1', color='green')
        nx.add_path(G, [0, 1, 2, 3])
        G.add_edge(1, 2, foo=3)
        G.graph['node_default'] = {'color': 'yellow'}
        G.graph['edge_default'] = {'foo': 7}
        fh = io.BytesIO()
        nx.write_gexf(G, fh)
        fh.seek(0)
        H = nx.read_gexf(fh, node_type=int)
        assert_equal(sorted(G.nodes()), sorted(H.nodes()))
        assert_equal(
            sorted(sorted(e) for e in G.edges()),
            sorted(sorted(e) for e in H.edges()))
        # Reading a gexf graph always sets mode attribute to either
        # 'static' or 'dynamic'. Remove the mode attribute from the
        # read graph for the sake of comparing remaining attributes.
        del H.graph['mode']
        assert_equal(G.graph, H.graph) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_gexf.py

示例6: gera_gexf_G

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def gera_gexf_G(self, G, path):
        # Antes de gerar esse formato, necessario adaptar alguns atributos do grafo
        G_adapt = G.copy()

        pos = nx.spring_layout(G_adapt, dim=4, scale=1000)
        
        for node in G_adapt.nodes:
            tipo_pessoa = G_adapt.nodes[node]['tipo_pessoa']

            G_adapt.nodes[node]['label'] = G_adapt.nodes[node]['nome']

            # Configura atributos de visualizacao necessarios para alguns leitores
            G_adapt.nodes[node]['viz'] = {'size':10}

            if tipo_pessoa == 1:
                if G_adapt.nodes[node]['situacao'] == '02':
                    G_adapt.nodes[node]['viz']['color'] = {'a':1,'r':1,'g':57,'b':155}
                else:
                    G_adapt.nodes[node]['viz']['color'] = {'a':1,'r':255,'g':0,'b':0}
            else:
                G_adapt.nodes[node]['viz']['color'] = {'a':1,'r':46,'g':125,'b':32}

            G_adapt.nodes[node]['viz']['position'] = {'x':pos[node][0],
                                                      'y':pos[node][1],
                                                      'z':5}

            # Converte cols para float, por incompatibilidade do nx com o numpy.float64
            for coluna in COL_FLOAT64:
                if coluna in G_adapt.nodes[node]:
                    G_adapt.nodes[node][coluna] = float(G_adapt.nodes[node][coluna])

        nx.write_gexf(G_adapt, path) 
开发者ID:fabioserpa,项目名称:CNPJ-full,代码行数:34,代码来源:rede_cnpj.py

示例7: write

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def write(self,path):
        nx.write_gexf(self.G, path) 
开发者ID:acsicuib,项目名称:YAFS,代码行数:4,代码来源:topology.py

示例8: get_weights

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def get_weights(self):
        G = self.G
        pr = self.pr
        max_pagerank = max(pr.itervalues())
        # get the largest count to scale weights between 0 and 1.

        t = datetime.datetime.now()
        ts = int(time.mktime(t.timetuple()))
        temp = tempfile.mktemp(prefix=str(ts), suffix=".gexf")

        nx.write_gexf(G, temp)

        for (k, v) in pr.iteritems():
            yield (k, float(v / max_pagerank)) 
开发者ID:UKPLab,项目名称:acl2017-interactive_summarizer,代码行数:16,代码来源:feedback_graph.py

示例9: WriteGraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def WriteGraph(g, graphName, colorLabels=None):

    if (graphName.find("gml") >= 0):
        nx.write_gml(g, graphName)
    elif (graphName.find("gexf") >= 0):
        nx.write_gexf(g, graphName)
    elif (graphName.find("graphml") >= 0):
        nx.write_graphml(g, graphName) 
开发者ID:mrvollger,项目名称:SDA,代码行数:10,代码来源:ABPUtils.py

示例10: test_write_read_simple_directed_graphml

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def test_write_read_simple_directed_graphml(self):
        G=self.simple_directed_graph
        fh=io.BytesIO()
        nx.write_gexf(G,fh)
        fh.seek(0)
        H=nx.read_gexf(fh)
        assert_equal(sorted(G.nodes()),sorted(H.nodes()))
        assert_equal(sorted(G.edges()),sorted(H.edges()))
        assert_equal(sorted(G.edges(data=True)),
                     sorted(H.edges(data=True)))
        self.simple_directed_fh.seek(0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:13,代码来源:test_gexf.py

示例11: test_serialize_ints_to_strings

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def test_serialize_ints_to_strings(self):
        G=nx.Graph()
        G.add_node(1,id=7,label=77)
        fh = io.BytesIO()
        nx.write_gexf(G,fh)
        fh.seek(0)
        H=nx.read_gexf(fh,node_type=int)
        assert_equal(H.nodes(),[7])
        assert_equal(H.node[7]['label'],'77') 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:test_gexf.py

示例12: test_bool

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def test_bool(self):
        G=nx.Graph()
        G.add_node(1, testattr=True)
        fh = io.BytesIO()
        nx.write_gexf(G,fh)
        fh.seek(0)
        H=nx.read_gexf(fh,node_type=int)
        assert_equal(H.node[1]['testattr'], True) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_gexf.py

示例13: write_gexf

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def write_gexf(G, path, encoding='utf-8',prettyprint=True,version='1.1draft'):
    """Write G in GEXF format to path.

    "GEXF (Graph Exchange XML Format) is a language for describing
    complex networks structures, their associated data and dynamics" [1]_.

    Parameters
    ----------
    G : graph
       A NetworkX graph
    path : file or string
       File or file name to write.
       File names ending in .gz or .bz2 will be compressed.
    encoding : string (optional)
       Encoding for text data.
    prettyprint : bool (optional)
       If True use line breaks and indenting in output XML.

    Examples
    --------
    >>> G=nx.path_graph(4)
    >>> nx.write_gexf(G, "test.gexf")

    Notes
    -----
    This implementation does not support mixed graphs (directed and undirected
    edges together).

    The node id attribute is set to be the string of the node label.
    If you want to specify an id use set it as node data, e.g.
    node['a']['id']=1 to set the id of node 'a' to 1.

    References
    ----------
    .. [1] GEXF graph format, http://gexf.net/format/
    """
    writer = GEXFWriter(encoding=encoding,prettyprint=prettyprint,
                        version=version)
    writer.add_graph(G)
    writer.write(path) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:42,代码来源:gexf.py

示例14: test_write_read_simple_directed_graphml

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def test_write_read_simple_directed_graphml(self):
        G = self.simple_directed_graph
        fh = io.BytesIO()
        nx.write_gexf(G, fh)
        fh.seek(0)
        H = nx.read_gexf(fh)
        assert_equal(sorted(G.nodes()), sorted(H.nodes()))
        assert_equal(sorted(G.edges()), sorted(H.edges()))
        assert_equal(sorted(G.edges(data=True)),
                     sorted(H.edges(data=True)))
        self.simple_directed_fh.seek(0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:13,代码来源:test_gexf.py

示例15: test_serialize_ints_to_strings

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_gexf [as 别名]
def test_serialize_ints_to_strings(self):
        G = nx.Graph()
        G.add_node(1, id=7, label=77)
        fh = io.BytesIO()
        nx.write_gexf(G, fh)
        fh.seek(0)
        H = nx.read_gexf(fh, node_type=int)
        assert_equal(list(H), [7])
        assert_equal(H.nodes[7]['label'], '77') 
开发者ID:holzschu,项目名称:Carnets,代码行数:11,代码来源:test_gexf.py


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