本文整理汇总了Python中igraph.Graph.vs["label"]方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.vs["label"]方法的具体用法?Python Graph.vs["label"]怎么用?Python Graph.vs["label"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.vs["label"]方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSimMSTs
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["label"] [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
示例2: build_graph
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["label"] [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
示例3: grid
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["label"] [as 别名]
def grid(p, q):
g = Graph(p * q)
g.vs["label"] = [str(x) for x in range(1, p*q+1)]
def v2i(i, j):
return i * q + j
def i2v(i):
return (i / q, i % q)
for i in range(p - 1):
for j in range(q):
# vertical
edge = (v2i(i, j), v2i(i + 1, j))
g.add_edges(edge)
for i in range(p):
for j in range(q - 1):
# horizontal
for i_ in range(i, p):
edge = (v2i(i, j), v2i(i_, j + 1))
g.add_edges(edge)
return g
示例4: outputDOT
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["label"] [as 别名]
def outputDOT(self, tree, filename):
root = tree.getroot()
g = Graph(0)
names = list()
self.__drawTree__(root, g, -1, names)
g.vs["label"] = names
layout = g.layout("tree")
visual_style = {}
visual_style["vertex_size"] = [20] * g.vcount()
visual_style["vertex_color"] = ["white"] * g.vcount()
visual_style["vertex_label"] = g.vs["label"]
visual_style["edge_width"] = [1] * g.vcount()
visual_style["layout"] = layout
visual_style["bbox"] = (2000, 900)
visual_style["margin"] = 50
visual_style["vertex_label_angle"] = [3 * math.pi / 2] * g.vcount()
visual_style["vertex_label_size"] = [10] * g.vcount()
g.write_dot(filename)
示例5: Graph
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["label"] [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