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


Python Graph.vs["color"]方法代码示例

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


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

示例1: getSimMSTs

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["color"] [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: build_graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["color"] [as 别名]
def build_graph(amplicons, relations):
    """
    Convert pairwise relations into a graph structure.
    """
    # Create vertices (= number of unique amplicons)
    g = Graph(len(amplicons))
    g.add_edges(relations)

    amplicon_ids = [amplicon[0] for amplicon in amplicons]
    abundances = [int(amplicon[1]) for amplicon in amplicons]
    minimum, maximum = min(abundances), max(abundances)

    # Determine canvas size
    if len(abundances) < 500:
        bbox = (1920, 1080)
    elif len(abundances) > 4000:
        bbox = (5760, 3240)
    else:
        bbox = (3840, 2160)

    # Compute node attributes
    node_colors = list()
    node_sizes = list()
    node_labels = list()
    print("Building graph", file=sys.stdout)
    for abundance in abundances:
        # Color is coded by a 3-tuple of float values (0.0 to 1.0)
        # Start from a max color in rgb(red, green, blue)
        max_color = (176, 196, 222)  # light steel blue
        color = [1.0 * (c + (255 - c) / abundance) / 255 for c in max_color]
        node_colors.append(color)
        node_size = 30 + (abundance * 70 / maximum)
        node_sizes.append(node_size)
        # Label nodes with an abundance greater than 10
        if abundance >= 10 or abundance == maximum:
            node_labels.append(str(abundance))
        else:
            node_labels.append("")  # Doesn't work with "None"

    g.vs["name"] = amplicon_ids
    g.vs["abundance"] = abundances
    g.vs["label"] = node_labels
    g.vs["color"] = node_colors
    g.vs["vertex_size"] = node_sizes

    return g, bbox
开发者ID:torognes,项目名称:swarm,代码行数:48,代码来源:graph_plot.py

示例3: Graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["color"] [as 别名]
from igraph import Graph,plot
g = Graph([(0,1), (0,2), (0,3), (0,4), (5,2), (3,5), (5,0), (4,3), (3,6)],directed = True)
g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
g.es["weight"] = [1,5,3,7,6,2,9,5,7]
g.vs["age"] = [25, 31, 18, 47, 22, 23, 50]
g.vs["gender"] = ["f", "m", "f", "m", "f", "m", "m"]
g.es["is_formal"] = [False, False, True, True, True, False, True, False, False]
layout = g.layout_fruchterman_reingold()
g.vs["label"] = g.vs["name"]
color_dict = {"m": "blue", "f": "pink"}
g.vs["color"] = [color_dict[gender] for gender in g.vs["gender"]]
# plot(g, layout = layout, bbox = (500, 500), margin = 20)
visual_style = {}
visual_style["vertex_size"] = 20
visual_style["vertex_color"] = [color_dict[gender] for gender in g.vs["gender"]]
visual_style["vertex_label"] = g.vs["name"]
visual_style["edge_width"] = [1 + 2 * int(is_formal) for is_formal in g.es["is_formal"]]
visual_style["layout"] = layout
visual_style["bbox"] = (300, 300)
visual_style["margin"] = 20
plot(g, **visual_style)

# print g
开发者ID:drstarry,项目名称:topic-river-flow,代码行数:25,代码来源:layout.py


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