當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。