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


Python Graph.layout_reingold_tilford方法代码示例

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


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

示例1: getSimMSTs

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import layout_reingold_tilford [as 别名]
    def getSimMSTs(self, inverse=True, plotGraph=True, root="UNK"):
        rootId1 = self.emb1.d[root]
        rootId2 = self.emb2.d[root]
        if inverse == True:
            d = -1
        else:
            d = 1
        g1 = minimum_spanning_tree(csr_matrix(d*self.s1))
        g2 = minimum_spanning_tree(csr_matrix(d*self.s2))

        a1 = g1.toarray()
        a2 = g2.toarray()

        if plotGraph==True:
            t1 = Graph()
            t2 = Graph()
            t3 = Graph()
            t1.add_vertices(self.emb1.vocab_size)
            t2.add_vertices(self.emb2.vocab_size)
            t3.add_vertices(self.emb1.vocab_size)
            t1.vs["color"] = "white"
            t2.vs["color"] = "white"
            t3.vs["color"] = "white"
            t1.vs["label"] = [w for w,i in sorted(self.emb1.d.items(), key=itemgetter(1))]
            t2.vs["label"] = [w for w,i in sorted(self.emb2.d.items(), key=itemgetter(1))]
            t3.vs["label"] = t1.vs["label"]
            for i in xrange(a1.shape[0]):
                for j in xrange(a1.shape[1]):
                    if a1[i,j] != 0:
                        t1.add_edge(i,j, weight=a1[i,j], color="blue")
                        t3.add_edge(i,j, weight=a1[i,j], color="blue")
            for i in xrange(a2.shape[0]):
                for j in xrange(a2.shape[1]):
                    if a2[i,j] != 0:
                        t2.add_edge(i,j, weight=a2[i,j], color="red")
                        if t3.are_connected(i,j): #edge in both MSTs
                            t3.es[i,j]["color"] = "black"
                        else:
                            t3.add_edge(i,j, weight=a1[i,j], color="red")
            layout1 = t1.layout_reingold_tilford(mode="in", root=rootId1)
            layout2 = t2.layout_reingold_tilford(mode="in", root=rootId2)
            layout3 = t3.layout_reingold_tilford(mode="in", root=rootId1)
            graphs = [Graph.GRG(10, 0.4) for _ in xrange(5)]
            figure = Plot(bbox=(0,0,2000,1000))
            figure.add(t1, layout=layout1, margin=100, bbox=(0,0,1000,1000))
            figure.add(t2, layout=layout2, margin=100, bbox=(1000,0,2000,1000))
            plotname1 = "plots/"+NAME+".mst_trees.png"
            figure.save(plotname1)
            plotname3 = "plots/"+NAME+".merged_mst.png"
            plot(t3, plotname3 , layout=layout3, bbox=(1000,1000), margin=100)
            print("\tSaved MST plots in '%s', '%s'" % (plotname1, plotname3))

        return t1,t2,t3
开发者ID:juliakreutzer,项目名称:loons,代码行数:55,代码来源:visualize.py

示例2: disp_tree

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import layout_reingold_tilford [as 别名]
def disp_tree(tree):

	from igraph import Graph, plot

	g = Graph(directed=True)
	g.add_vertices(len(tree))

	g.vs['label'] = [node.name for node in tree]

	nodes_to_add = set([0])
	while len(nodes_to_add) != 0:

		i_node = nodes_to_add.pop()
		node = tree[i_node]
		g.vs['label'][i_node] = node.name

		left_node = node.left_child
		right_node = node.right_child

		if left_node != None:
			i_left = tree.index(left_node)
			g.add_edges((i_node, i_left))
			nodes_to_add.add(i_left)
		
		if right_node != None:
			i_right = tree.index(right_node)
			g.add_edges((i_node, i_right))
			nodes_to_add.add(i_right)

	layout = g.layout_reingold_tilford(root=0)
	plot(g, layout=layout, bbox=(0, 0, 3000, 1000))
开发者ID:rffrancon,项目名称:Checking-Solutions-For-GLTI,代码行数:33,代码来源:utilities.py

示例3: plotTreeFromString

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import layout_reingold_tilford [as 别名]
def plotTreeFromString(treeString, colordict, plotFile):
    """
    Plots a tree from the 'brackets tree' format
    :param treeString:
    :param colordict: defines the colors of the nodes by label (e.g. 1 to 5)
    :param plotFile: output file (.png)
    :return:
    """
    g = Graph()
    splitted = treeString.split("(")

    level = -1
    parents = dict()
    parentIds = dict()
    levelCount = dict()
    for part in splitted:
        if len(part)<1:
            continue
        else: #label follows
            level+=1
            count = levelCount.get(level,0)
            levelCount[level] = count+1
            #print "level %d" % level
            label = part[0]
            #print part.split()
            if len(part.split())>1: #leaf node
                label, wordPlusEnding = part.split()
                #print part, "at leaf"
                endings = wordPlusEnding.count(")")
                word = wordPlusEnding.strip(")")
                g.add_vertex(label=word, color=colordict[int(label)])
                #print "added node %d" % (len(g.vs)-1)
                currentNode = len(g.vs)-1
                p = parents[level-1]
                g.add_edge(currentNode,p)#add edge to parent
                #print "added edge %d-%d" % (len(g.vs)-1, parentIds[level-1])
                level-=endings
                #print "word", word
            else:
                g.add_vertex(label=label, color=colordict[int(label)])
                currentNode = g.vs[len(g.vs)-1]
                #print "added node %d" % (len(g.vs)-1)
                if level != 0:
                    p = parents[level-1]
                    g.add_edge(currentNode,p)#add edge to parent
                    #print "added edge %d-%d" % (len(g.vs)-1, parentIds[level-1])

                parent = currentNode
                parentId = len(g.vs)-1
                parents[level] = parent
                parentIds[level] = parentId
                print parentIds

        print g.summary()
        layout = g.layout_reingold_tilford(mode="in", root=0)
        plot(g, plotFile, layout=layout, bbox = (2000, 1000), margin = 100)
开发者ID:juliakreutzer,项目名称:wtfrnn,代码行数:58,代码来源:plotTree.py


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