• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python networkx.write_graphml函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: get_topology

def get_topology():
    G = nx.Graph()
    G.add_node("poi-1", packetloss=0.0, ip="0.0.0.0", geocode="US", bandwidthdown=17038, bandwidthup=2251, type="net", asn=0)
    G.add_edge("poi-1", "poi-1", latency=50.0, jitter=0.0, packetloss=0.05)
    s = StringIO()
    nx.write_graphml(G, s)
    return s.getvalue()
开发者ID:4sp1r3,项目名称:shadow,代码行数:7,代码来源:generate_example_config.py


示例2: create_joined_multigraph

def create_joined_multigraph():
    G=nx.DiGraph()
    upp=nx.read_graphml('upperlevel_hashtags.graphml')
    for ed in upp.edges(data=True):
        G.add_edge(ed[0],ed[1],attr_dict=ed[2])
        G.add_edge(ed[1],ed[0],attr_dict=ed[2])
    mid=nx.read_graphml('friendship_graph.graphml')
    for ed in mid.edges(data=True):
        G.add_edge(ed[0],ed[1],attr_dict=ed[2]) 
    inter=nx.read_graphml('interlevel_hashtags.graphml')
    for ed in inter.edges(data=True):
        G.add_edge(ed[0],ed[1],attr_dict=ed[2]) 
        G.add_edge(ed[1],ed[0],attr_dict=ed[2])
    down=nx.read_graphml('retweet.graphml')
    mapping_f={}
    for i,v in enumerate(down.nodes()):
        mapping_f[v]='%iretweet_net' %i
    for ed in down.edges(data=True):
        G.add_edge(mapping_f[ed[0]],mapping_f[ed[1]],attr_dict=ed[2]) 

    for nd in mid.nodes():
        if nd in mapping_f:
            G.add_edge(nd,mapping_f[nd])
            G.add_edge(mapping_f[nd],nd)
    nx.write_graphml(G,'joined_3layerdigraph.graphm')
    return G,upp.nodes(),mid.nodes(),mapping_f.values()
开发者ID:SergiosLen,项目名称:TwitterMining,代码行数:26,代码来源:joiner.py


示例3: main

def main():
    files = []
    for i in range(1,26): 
        files.append("db/Minna_no_nihongo_1.%02d.txt" % i)
    for i in range(26,51): 
        files.append("db/Minna_no_nihongo_2.%02d.txt" % i)


    words = get_words_from_files(files)

    G=nx.Graph()

    for w in words:
        G.add_node(w)
        G.node[w]['chapter'] = words[w]['chapter']
        G.node[w]['kana'] = words[w]['kana']
        G.node[w]['meaning'] = words[w]['meaning'][:-1]

    for word1, word2 in itertools.combinations(words,2):
        for w1 in word1[:-1]:
            #print w1.encode('utf-8')
            #print ud.name(w1)
            if "CJK UNIFIED" in ud.name(w1) and w1 in word2:
                #print word1.encode('utf-8'), word2.encode('utf-8')
                G.add_edge(word1, word2)
                break
    
    #G = nx.connected_component_subgraphs(G)
    G = sorted(nx.connected_component_subgraphs(G), key = len, reverse=True)
    #print len(G)
    #nx.draw(G)
    nx.write_graphml(G[0], "kanjis.graphml", encoding='utf-8', prettyprint=True)
开发者ID:yescalona,项目名称:KanjiNetwork,代码行数:32,代码来源:kanjis.py


示例4: lei_vs_lei

def lei_vs_lei(nedges=None):
    """
    Grafo de todas com todas (leis)
    """
    # Verão original Flávio comentada
    # curgrafo.execute('select lei_id_1,esfera_1,lei_1,lei_id_2,esfera_2, lei_2, peso from vw_gr_lei_lei where  peso >300 and lei_id_2>2')
    # curgrafo.execute('select lei_id_1,lei_tipo_1,lei_nome_1,lei_id_2,lei_tipo_2, lei_nome_2, peso from vw_gr_lei_lei where lei_count <= 20 and lei_id_1 = 1 and lei_id_2 <= 20 limit 0,1000')
    # curgrafo.execute('select lei_id_1,lei_tipo_1,lei_nome_1,lei_id_2,lei_tipo_2, lei_nome_2, peso from vw_gr_lei_lei where lei_count <= 8 and lei_id_1 <= 20 and lei_id_2 <= 20 limit 0,1000')
    curgrafo.execute('select lei_id_1,esfera_1,lei_1,lei_id_2,esfera_2, lei_2, peso from vw_gr_lei_lei where lei_count <= 10 and lei_id_1 <= 50 and lei_id_2 <= 200 limit 0,10000')
    if not nedges:
        res = curgrafo.fetchall()
        nedges = len(res)
    else:
        res = curgrafo.fetchmany(nedges)
    eds = [(i[0],i[3],i[6]) for i in res]
    G = nx.Graph()
    #eds = [i[:3] for i in res]
    G.add_weighted_edges_from(eds)
    print "== Grafo Lei_Lei =="
    print "==> Order: ",G.order()
    print "==> # Edges: ",len(G.edges())
    # Adding attributes to nodes
    for i in res:
        G.node[i[0]]['esfera'] = i[1]
        G.node[i[0]]['lei'] = i[2]
        G.node[i[3]]['esfera'] = i[4]
        G.node[i[3]]['lei'] = i[5]
    nx.write_graphml(G,'lei_lei.graphml')
    nx.write_gml(G,'lei_lei.gml')
    nx.write_pajek(G,'lei_lei.pajek')
    nx.write_dot(G,'lei_lei.dot')
    return G,res
开发者ID:Ralpbezerra,项目名称:Supremo,代码行数:32,代码来源:grafos.py


示例5: export_graph

def export_graph(G, write_filename):
    write_dir = "./output/" + write_filename + "/"
    if not os.path.isdir(write_dir):
        os.mkdir(write_dir)


    # Remove pho edge weights
    for n1 in G.edge:
        for n2 in G.edge[n1]:
            G.edge[n1][n2]={}
    print("\twriting gml")
    for node in G.nodes_iter():
        for key, val in list(G.node[node].items()):
            G.node[node][key]=int(val)
    nx.write_gml(G, write_dir + write_filename + ".gml")
    print("\twriting graphml")
    nx.write_graphml(G, write_dir + write_filename + ".graphml")
    print("\twriting edgelist")
    f = open(write_dir + write_filename + ".edgelist","w")
    for edge in G.edges_iter():
        f.write("\t".join([str(end) for end in list(edge)[:2]])+"\n")
    f.close()
    f = open(write_dir + write_filename + ".nodelist","w")
    print("\twriting nodelist")
    f.write("\t".join(["node_id"] + node_attributes) + "\n")
    for node in G.nodes_iter():
        f.write("\t".join([str(node)] + [str(G.node[node][attribute]) for attribute in node_attributes]) + "\n")
开发者ID:maxvogel,项目名称:NetworKit-mirror2,代码行数:27,代码来源:FacebookParser.py


示例6: save_graph

    def save_graph(self, graphname, fmt='edgelist'):
        """
        Saves the graph to disk

        **Positional Arguments:**

                graphname:
                    - Filename for the graph

        **Optional Arguments:**

                fmt:
                    - Output graph format
        """
        self.g.graph['ecount'] = nx.number_of_edges(self.g)
        g = nx.convert_node_labels_to_integers(self.g, first_label=1)
        if fmt == 'edgelist':
            nx.write_weighted_edgelist(g, graphname, encoding='utf-8')
        elif fmt == 'gpickle':
            nx.write_gpickle(g, graphname)
        elif fmt == 'graphml':
            nx.write_graphml(g, graphname)
        else:
            raise ValueError('edgelist, gpickle, and graphml currently supported')
        pass
开发者ID:gkiar,项目名称:ndmg,代码行数:25,代码来源:graph.py


示例7: save_celltype_graph

    def save_celltype_graph(self, filename="celltype_conn.gml", format="gml"):
        """
        Save the celltype-to-celltype connectivity information in a file.
        
        filename -- path of the file to be saved.

        format -- format to save in. Using GML as GraphML support is
        not complete in NetworkX.  

        """
        start = datetime.now()
        if format == "gml":
            nx.write_gml(self.__celltype_graph, filename)
        elif format == "yaml":
            nx.write_yaml(self.__celltype_graph, filename)
        elif format == "graphml":
            nx.write_graphml(self.__celltype_graph, filename)
        elif format == "edgelist":
            nx.write_edgelist(self.__celltype_graph, filename)
        elif format == "pickle":
            nx.write_gpickle(self.__celltype_graph, filename)
        else:
            raise Exception("Supported formats: gml, graphml, yaml. Received: %s" % (format))
        end = datetime.now()
        delta = end - start
        config.BENCHMARK_LOGGER.info(
            "Saved celltype_graph in file %s of format %s in %g s"
            % (filename, format, delta.seconds + delta.microseconds * 1e-6)
        )
        print "Saved celltype connectivity graph in", filename
开发者ID:BhallaLab,项目名称:thalamocortical,代码行数:30,代码来源:traubnet.py


示例8: finish_graph

def finish_graph():
	nx.draw(g)
	file_name='host_hops1.png'
	file_nameg='host_hops1.graphml'
	plt.savefig(file_name)
	nx.write_graphml(g, file_nameg)
	print ("Graph Drawn")
开发者ID:aravindhsampath,项目名称:Grad_school_course_Projects,代码行数:7,代码来源:Host_hops.py


示例9: to_file

 def to_file(self, name_graphml='AST2NX.graphml'):
     """ write to a graphml file which can be read by a lot of professional visualization tools such as Cytoscape.
     """
     if name_graphml.endswith('.graphml'):
         nx.write_graphml(self.NetworkX, name_graphml)
     else:
         nx.write_graphml(self.NetworkX, name_graphml + '.graphml')
开发者ID:TengyuMaVandy,项目名称:foyer,代码行数:7,代码来源:ast2nx.py


示例10: draw_base_graph

 def draw_base_graph(self):
     print 'writing base graphml ...'
     G = nx.Graph()
     G.add_nodes_from(xrange(self.num_nodes))
     G.add_edges_from(self.E_base)
     nx.write_graphml(G,'exodus.graphml')
     print 'done ... (load in Gephi)'
开发者ID:abhishekpant93,项目名称:DTN-broadcast,代码行数:7,代码来源:exodus.py


示例11: build_graph

    def build_graph(self):
        self.node_list = [self.like_minded_friend, self.books_reco_from, self.movies_reco_from, self.music_reco_from,
                          self.sport_reco_from, 'Read a book? Ask me', 'Watch a movie? Ask me', 'Sing along with',
                          'Sports arena?', 'Similar tastes?']
        #self.node_list.append(self.friends_likes[self.like_minded_friend][:10])
        self.node_list.append(self.user_name)

        self.G.add_nodes_from(self.node_list)

        self.G.add_edge(self.user_name, 'Similar tastes?', color = 'purple')
        self.G.add_edge('Similar tastes?', self.like_minded_friend,color = 'purple' )

        self.G.add_edge(self.user_name, 'Read a book? Ask me', color = 'blue')
        self.G.add_edge('Read a book? Ask me', self.books_reco_from, color = 'blue')

        self.G.add_edge(self.user_name, 'Watch a movie? Ask me', color = 'green')
        self.G.add_edge('Watch a movie? Ask me', self.movies_reco_from, color = 'green')

        self.G.add_edge(self.user_name, 'Sing along with', color = 'yellow')
        self.G.add_edge('Sing along with', self.music_reco_from, color = 'yellow')

        self.G.add_edge(self.user_name, 'Sports arena?', color = 'orange')
        self.G.add_edge('Sports arena?', self.sport_reco_from, color = 'orange')

        self.G.add_edge(self.user_name, 'Pages you might like!', color = 'red')
        for node in self.friends_likes[self.like_minded_friend][:10]:
            self.G.add_edge('Pages you might like', node, color = 'red')


        nx.write_graphml(self.G, 'FBViz' + ".graphml")
开发者ID:supriyaanand,项目名称:FBViz,代码行数:30,代码来源:FBViz.py


示例12: start

    def start(self):
        for id in self.oidRootNamePairs:
            self.oidNamePairs,currIDs=Utils.getoidNames(self.oidNamePairs,id,Def.typ)
            Utils.report('Processing current IDs: '+str(currIDs))
            flip=(Def.typ=='fr')
            self.addDirectedEdges(id, currIDs,flip=flip)
            n=len(currIDs)
            Utils.report('Total amount of IDs: '+str(n))
            c=1
            for cid in currIDs:
                Utils.report('\tSub-level run: getting '+Def.typ2,str(c)+'of'+str(n)+Def.typ+cid)
                self.oidNamePairs,ccurrIDs=Utils.getoidNames(self.oidNamePairs,cid,Def.typ2)
                self.addDirectedEdges( cid, ccurrIDs)
                c=c+1
        for id in self.oidRootNamePairs:
            if id not in self.oidNamePairs:
                self.oidNamePairs[id]=self.oidRootNamePairs[id]
        self.labelNodes(self.oidNamePairs)
        Utils.report(nx.info(self.DG))

        now = datetime.datetime.now()
        timestamp = now.strftime("_%Y-%m-%d-%H-%M-%S")

        fname=UserID._name.replace(' ','_')
        nx.write_graphml(self.DG, '/'.join(['reports',fname+'_google'+Def.typ+'Friends_'+timestamp+".graphml"]))
        nx.write_edgelist(self.DG, '/'.join(['reports',fname+'_google'+Def.typ+'Friends_'+timestamp+".txt"]),data=False)
开发者ID:robomotic,项目名称:gplusgraph,代码行数:26,代码来源:GPlusGraph.py


示例13: create_graph

def create_graph():
    G = nx.Graph()
    data = []
    reposts = []
    client = MongoClient()
    db = client["vk_db"]
    collection = db["valid_communities_info"]
    result = collection.find()
    for res in result:
        data.append(res)

    db=client["reposts"]
    collection = db["general"]
    answer = collection.find()
    for res in answer:
        reposts.append(res)

    for each in data:
        G.add_node(each["screen_name"])
        G.node[each["screen_name"]]['weight'] = each["weight"]

    for each in reposts:
        G.add_edge(get_name_by_id(each["owner"]), get_name_by_link(each["link"]), weight=each["times"])

    nx.write_graphml(G,'vk.graphml')
开发者ID:pphator,项目名称:vk_python,代码行数:25,代码来源:MakingGraph.py


示例14: main

def main():
    
    print "time_evol module is the main code."
    ## to import a network of 3-node example
    EDGE_FILE = 'C:\Boolean_Delay_in_Economics\Manny\EDGE_FILE.dat'
    NODE_FILE = 'C:\Boolean_Delay_in_Economics\Manny\NODE_FILE.dat'
    
    net = inet.read_network_from_file(EDGE_FILE, NODE_FILE)
    nodes_list = inet.build_nodes_list(NODE_FILE)
    '''
    ## to obtain time series data for all possible initial conditions for 3-node example network
    timeSeriesData = ensemble_time_series(net, nodes_list, 2, 10)#, Nbr_States=2, MAX_TimeStep=20)
    initState = 1
    biStates = decimal_to_binary(nodes_list, initState)
    print 'initial state', biStates
    
    ## to print time series data for each node: a, b, c starting particualr decimal inital condition 1
    print 'a', timeSeriesData['a'][1]
    print 'b', timeSeriesData['b'][1]
    print 'c', timeSeriesData['c'][1]
    '''
    
    ## to obtain and visulaize transition map in the network state space
    decStateTransMap = net_state_transition(net, nodes_list)
    nx.write_graphml(decStateTransMap,'C:\Boolean_Delay_in_Economics\Manny\Results\BDE.graphml')
    '''
开发者ID:SES591,项目名称:Manny_Economics,代码行数:26,代码来源:time_evol.py


示例15: output_graph

def output_graph(mps, mp_data, edges):

  G=nx.Graph()

  # Define the nodes
  for mp in mps:
    G.add_node(mp, label=mp_data[mp]["name"], party=mp_data[mp]["party"], constituency=mp_data[mp]["constituency"])

  # Process all known edges
  for (mp_tuple,agr_data) in edges.items():

    agreements = agr_data[0]
    agreement_rate = agr_data[2]

    # Depending on the selection criteria, filter out relationships
    if agreement_rate < 85:
      continue    

    # Determine a (normalized) weight, again depending on the desired graph
    # edge_wt = agreements
    range_min = 85
    range_max = 100
    weight_base = agreement_rate - range_min
    edge_wt = ( float(weight_base) / float(range_max - range_min) )

    G.add_edge(mp_tuple[0],mp_tuple[1], agreement=agreement_rate, weight=edge_wt )

  nx.write_graphml(G, "mp_agreement.graphml")
开发者ID:j-siddle,项目名称:uk-mp-voting,代码行数:28,代码来源:query.py


示例16: graphMLfromCSV

 def graphMLfromCSV(self, csvfile, filter):     
 
    filter_score = float(filter)
    if filter_score is False:
       filter_score = float(0.0)
       
    csv = self.csv.csvaslist(csvfile)      
    graphfile = csvfile.split('.', 1)[0] + "-graph.xml"      
    nodes = []      
    
    for line in csv:
       #we should have a correctly formatted CSV to work with
       if 'score' in line and 'source' in line and 'target' in line:
          source = line[u'source']
          target = line[u'target']
          score = float(line[u'score']) / 100
          if score >= filter_score:
             if source not in nodes:
                self.G.add_node(source)
                nodes.append(source)
             if target not in nodes:
                self.G.add_node(target)
                nodes.append(target)
             self.G.add_edge(source,target,weight=score)
             print score
    nx.write_graphml(self.G, graphfile)
开发者ID:ross-spencer,项目名称:sscompare,代码行数:26,代码来源:graphfuzzy.py


示例17: test_write_read_attribute_numeric_type_graphml

    def test_write_read_attribute_numeric_type_graphml(self):
        from xml.etree.ElementTree import parse

        G = self.attribute_numeric_type_graph
        fh = io.BytesIO()
        nx.write_graphml(G, fh, infer_numeric_types=True)
        fh.seek(0)
        H = nx.read_graphml(fh)
        fh.seek(0)

        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.attribute_numeric_type_fh.seek(0)

        xml = parse(fh)
        # Children are the key elements, and the graph element
        children = xml.getroot().getchildren()
        assert_equal(len(children), 3)

        keys = [child.items() for child in children[:2]]

        assert_equal(len(keys), 2)
        assert_in(('attr.type', 'double'), keys[0])
        assert_in(('attr.type', 'double'), keys[1])
开发者ID:JaimieMurdock,项目名称:networkx,代码行数:26,代码来源:test_graphml.py


示例18: main

def main():    
    universe = nx.read_graphml(sys.argv[1])
    
    beings = filter(lambda x: x[1]["type"] == "Being", universe.nodes(data=True))
    clients = filter(lambda x: x[1]["type"] == "client", universe.nodes(data=True))
    firm = filter(lambda x: x[1]["type"] == "firm", universe.nodes(data=True))        
    print len(beings)
    print len(clients)
    print len(firm)
    
    for b in beings:
        ns = nx.neighbors(universe,b[0])
        rep = ns[0]
        for n in ns[1:]:
            for nn in nx.neighbors(universe,n):
                universe.add_edge(rep,nn) #doesn't preserve directions or properties, yolo
            universe.remove_node(n)
        universe.remove_node(b[0])
        
    beings = filter(lambda x: x[1]["type"] == "Being", universe.nodes(data=True))
    clients = filter(lambda x: x[1]["type"] == "client", universe.nodes(data=True))
    firm = filter(lambda x: x[1]["type"] == "firm", universe.nodes(data=True))        
    print len(beings)
    print len(clients)
    print len(firm)
            
    nx.write_graphml(universe,"simplified-{}.graphml".format(int(time.time())))
开发者ID:influence-usa,项目名称:lobbying_federal_domestic,代码行数:27,代码来源:simplify.py


示例19: produce_graph

def produce_graph(cutoff, transform):
    G = nx.Graph()
    allusers = set()
    for c in user_relations:
        allusers.add(c[0])
        allusers.add(c[1])
    for u in allusers:
        G.add_node(u, weight = user_influence[u])
    user_top = {}
    for c in user_relations:
        user1 = c[0]
        user2 = c[1]
        score = user_relations[c]
        if user1 not in user_top:
            user_top[user1] = {}
        if user2 not in user_top:
            user_top[user2] = {}
        user_top[user1][user2] = score
    for u in user_top:
        top5 = dict(sorted(user_top[u].items(), key=lambda x: x[1], reverse=True)[:5])
        for j in top5:
            G.add_edge(u, j, weight = user_top[u][j])
            
##        user_top[c[0]]
##        if user_relations[c] > cutoff:
##            G.add_edge(c[0], c[1], weight = transform(user_relations[c]))
    nx.write_graphml(G, 'graph' + time.strftime("%Y-%m-%d-%H%M%S", time.gmtime()) + '.graphml')
开发者ID:colblitz,项目名称:dragonnest,代码行数:27,代码来源:network.py


示例20: filterNet

def filterNet(DG,mindegree):
	if addUserFriendships==1:
		DG=addFocus(DG,user,typ)
	mindegree=int(mindegree)
	filter=[]
	filter= [n for n in DG if DG.degree(n)>=mindegree]
	H=DG.subgraph(filter)
	print "Filter set:",filter
	print H.order(),H.size()
	LH=labelGraph(H,filter)

	now = datetime.datetime.now()
	ts = now.strftime("_%Y-%m-%d-%H-%M-%S")
  
	nx.write_graphml(H, '/'.join([path,agent,typ,tt+"degree"+str(mindegree)+ts+".graphml"]))

	nx.write_edgelist(H, '/'.join([path,agent,typ,tt+"degree"+str(mindegree)+ts+".txt"]),data=False)
	#delimiter=''

	#indegree=sorted(nx.indegree(DG).values(),reverse=True)
	indegree=H.in_degree()
	outdegree=H.out_degree()

	inout = [indegree, outdegree]
	inoutpair = {}
	for k in indegree.iterkeys():
		inoutpair[k] = tuple(inoutpair[k] for inoutpair in inout)
    
	fig = plt.figure()
	ax = fig.add_subplot(111)
	#ax.plot(indegree,outdegree, 'o')
	#ax.set_title('Indegree vs outdegree')
	degree_sequence=sorted(indegree.values(),reverse=True)
	plt.loglog(degree_sequence)
	plt.savefig( '/'.join([path,agent,typ,tt+"degree"+str(mindegree)+"outdegree_histogram.png"]))
开发者ID:DPCollins,项目名称:newt,代码行数:35,代码来源:nxGdfFilter.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python networkx.write_multiline_adjlist函数代码示例发布时间:2022-05-27
下一篇:
Python networkx.write_gpickle函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap