本文整理汇总了Python中igraph.Graph.layout方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.layout方法的具体用法?Python Graph.layout怎么用?Python Graph.layout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.layout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: outputDOT
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import layout [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)
示例2: range
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import layout [as 别名]
minDegree = 5
for e in g.es:
if e["weight"] < 10000.0:
g.delete_edges(e)
for x in range(8):
print "removing:"
for v in g.vs:
if v.degree() < minDegree:
g.delete_vertices(v)
print "graph contains ", len(g.es), "edges"
print "graph contains ", len(g.vs), "vertices"
drawPNG = True
if drawPNG:
print "drawing begins:"
layout = g.layout('kk')
width, height = 5000, 5000
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context(surface)
ctx.scale(width, height)
ctx.rectangle(0, 0, 1, 1)
ctx.set_source_rgba(0, 0, 0, 0)
ctx.fill()
plot = igraph.plot(g, surface,
vertex_shape="rect", vertex_label=g.vs["name"],
edge_width=g.es["weight"],
bbox=(width, height), layout=layout)
# plot = igraph.plot(g, surface, bbox=(width, height), layout=layout)
plot.background = None
plot.redraw()
示例3: __init__
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import layout [as 别名]
#.........这里部分代码省略.........
# remove edges outside of t_window
self.graph.delete_edges(edges_to_trim)
# identify vertices with 0 degree to delete
vertices_to_trim = self.graph.vs.select(_degree=0)
if self.verbose: print("Vertices to trim: "+str(vertices_to_trim._name_index))
self.graph.delete_vertices(vertices_to_trim)
def add_tweet(self,hash_tag_tuple,epoch_time):
"""
Adds tweet to hash tag graph and updates graph such that it only contains tweets
withing window_duration of the latest in time tweet. If tweet is outside of the window_duration
than it is not added to the graph and nothing happens
:return:
"""
# Check if tweet is in order, inside the window duration, or outside
t_diff = self.latest_time - epoch_time > self.t_window
if t_diff <= self.t_window:
self.latest_time = max(epoch_time,self.latest_time)
current_vertices = self.graph.vs._name_index
if self.verbose:
print('Graph name index: '+str(current_vertices))
print('Graph name index type: '+str(type(current_vertices)))
# current vertivces will have none type when it is initilazed empty
if current_vertices is not None:
# Add hashtag to graph as vertex, if its already exists, nothing happens
for hash_tag in hash_tag_tuple:
# only add hashtag if it isn't already in the graph
if hash_tag not in current_vertices:
if self.verbose: print("Adding Vertex: "+str(hash_tag))
self.graph.add_vertex(name=hash_tag)
else:
# Add hashtag to graph as vertex, if its already exists, nothing happens
for hash_tag in hash_tag_tuple:
if self.verbose: print("Adding Vertex: "+str(hash_tag))
self.graph.add_vertex(name=hash_tag)
# Add edges with associated epoch time
for edge in combinations(hash_tag_tuple,r=2):
if self.verbose: print('Adding Edge Pair:'+str(edge)+" Time:"+str(epoch_time))
self.graph.add_edge(source=edge[0],target=edge[1],time=epoch_time)
self.trim()
# if tweet is outside of the time window than toss it
else:
return
return
def get_mean_degree(self):
"""
Compute the average degree
:return: np.float, average graph degree
"""
return np.mean(self.graph.degree())
def draw_graph(self,path):
"""
Utlity for visualizing the graph.
:return: 0
"""
print("Drawing HashTag Graph!")
layout = self.graph.layout("kk")
self.graph.vs["label"] = self.graph.vs["name"]
visual_style = {}
visual_style["bbox"] = (1600,1600)
visual_style["vertex_size"] = 10
visual_style["edge_width"] = 1
visual_style["edge_color"] = 'blue'
visual_style["layout"] = layout
visual_style["margin"] = 100
graph_plot = plot(self.graph, **visual_style)
graph_plot.save(fname=path)
return 0