本文整理汇总了Python中graphviz.Graph.edge方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.edge方法的具体用法?Python Graph.edge怎么用?Python Graph.edge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphviz.Graph
的用法示例。
在下文中一共展示了Graph.edge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
class render:
def __init__(self,our_graph,wt_dist,colour_list,tup=[-1,-1]):
self.G = Graph(format='png')
self.edgeList = []
#i=0
for vertex in our_graph.vertList:
self.G.node(str(vertex),label='INF' if wt_dist[vertex]==10000000 else str(wt_dist[vertex]),color='red' if colour_list[vertex] else 'black')
for adjvertices in our_graph.vertList[vertex].connectedTo:
if tup==[vertex,adjvertices] or tup==[adjvertices,vertex]:
cl='green'
else:
cl='black'
#print vertex.connectedTo[adjvertices]
if our_graph.vertList[vertex].connectedTo[adjvertices][1] in self.edgeList:
pass
else:
self.G.edge(str(vertex),str(adjvertices),str(our_graph.vertList[vertex].connectedTo[adjvertices][0]),color=cl)
self.edgeList.append(our_graph.vertList[vertex].connectedTo[adjvertices][1])
#self.G.edge(str(vertex),str((vertex+1)%10),label='edge',color='green')
self.G.view()
示例2: create_interactions_graph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def create_interactions_graph(clauses, f):
dot = GGraph(comment='Interactions graph', engine='sfdp')
seen_vars = set()
edges_between_vars = defaultdict(int)
for clause in clauses:
for lit in clause:
var = f(lit)
if var not in seen_vars:
seen_vars.add(var)
dot.node(str(var), label=str(var))
for clause in clauses:
l = len(clause)
for i in xrange(l):
for j in xrange(i+1, l):
edges_between_vars[(str(f(clause[i])), str(f(clause[j])))] += 1
for interacting_vars, weight in edges_between_vars.iteritems():
dot.edge(interacting_vars[0], interacting_vars[1], weight=str(weight))
print edges_between_vars
dot = _apply_styles(dot, styles)
# print dot.source
dot.render(os.path.join('images', 'interactions_graph.gv'), view=True)
示例3: visualize_countries_together_in_item
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def visualize_countries_together_in_item(data, start_time_str=None, end_time_str=None, newspaper_str='*'):
countries_together_dict = _get_countries_together_in_items(data)
# print 'countries_together_dict:', countries_together_dict
dot = Graph(comment='Countries together in item graph', engine='sfdp')
seen_countries = set()
edges_between_countries = defaultdict(int)
## Building the graph
for ID_and_feed, countries in countries_together_dict.iteritems():
countries_list = list(countries)
for country in countries_list:
if country != '' and country not in seen_countries:
dot.node(country, label=country)
seen_countries.add(country)
for i in xrange(len(countries)):
for j in xrange(i+1, len(countries)):
fst = min(countries_list[i], countries_list[j])
snd = max(countries_list[i], countries_list[j])
edges_between_countries[(fst, snd)] += 1
for edge_endpoints, edge_weight in edges_between_countries.iteritems():
dot.edge(edge_endpoints[0], edge_endpoints[1], weight=str(edge_weight))
print 'seen_countries:', seen_countries
print 'edges_between_countries:', edges_between_countries
dot = _apply_styles(dot, styles)
# print dot.source
out_dirname = newspaper_str.replace('*', '').replace('!', '').replace('[', '').replace(']', '')
out_filename = ('countries_together_in_item_%s_%s.gv' % (start_time_str, end_time_str)).replace(':', '-')
dot.render(os.path.join('images', out_dirname, out_filename), view=False)
示例4: render_graph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def render_graph(graph, name=None, directory=None, fill_infected='green3'):
""" Render a user graph to an SVG file. Infected nodes are colored
appropriately.
Parameters:
-----------
graph : UserGraph
The graph to render.
name : str
A name for the graph.
directory : str
The directory to render to.
fill_infected : str
The fill color for infected nodes.
"""
dot = Graph(name=name, format='svg', strict=True)
for user in graph.users():
if user.metadata.get('infected', False):
dot.attr('node', style='filled', fillcolor=fill_infected)
dot.node(unicode(user.tag))
dot.attr('node', style='')
for user in graph.users():
for neighbor in user.neighbors:
dot.edge(unicode(user.tag), unicode(neighbor.tag))
dot.render(directory=directory, cleanup=True)
示例5: visualize
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def visualize(self):
l = len(self.top_result)
connections = dict()
tags = dict()
for i in range(l - 1):
for j in range(1, l):
if i != j:
key = (i, j)
message_list = self.get_message_list_between(self.top_result[i], self.top_result[j])
tag_cloud = self.subject.calculate_tag_cloud(message_list)
tags[key] = self.get_top_tag_cloud(tag_cloud, 5)
# DOT language
dot = GraphV(comment = "Information Flow - Enron")
for i in range(l):
dot.node(str(i), self.top_result[i] + " - " + self.company.get_role(self.top_result[i]))
for (edge, tag) in tags.iteritems():
node_1 = edge[0]
node_2 = edge[1]
note = ", ".join(tag)
print note
dot.edge(str(node_1), str(node_2), label=note)
dot.render('test-output/round-table.gv', view=False)
示例6: graph_draw
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def graph_draw(nodes, edges, name):
g = Graph(name, format="png")
for node in nodes:
g.node(str(node))
for edge in edges:
x = edge.split(' ')[0]
y = edge.split(' ')[1]
g.edge(x, y)
g.view()
示例7: __str__
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def __str__(self):
A = Graph()
for vertice in self.meuGrafo.nodes_iter(data=False):
A.node(vertice.encode("utf8"))
for aresta_A, aresta_B, dados_aresta in self.meuGrafo.edges_iter(data=True):
peso_aresta = dict((chave, str(valor)) for chave, valor in dados_aresta.items())
peso_aresta['label'] = peso_aresta['weight']
del peso_aresta['weight']
A.edge(aresta_A.encode("utf8"), aresta_B.encode("utf8"), **peso_aresta)
return A.source
示例8: renderiza_grafo
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def renderiza_grafo(self, lugar_para_gerar, nome_grafo):
A = Graph(comment=nome_grafo, filename=(lugar_para_gerar + '/Grafo.gv'), engine='dot')
for vertice in self.meuGrafo.nodes_iter(data=False):
A.node(vertice.encode("utf8"))
for aresta_A, aresta_B, dados_aresta in self.meuGrafo.edges_iter(data=True):
peso_aresta = dict((chave, str(valor)) for chave, valor in dados_aresta.items())
peso_aresta['label'] = peso_aresta['weight']
del peso_aresta['weight']
A.edge(aresta_A, aresta_B, **peso_aresta)
A.view()
示例9: plot
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def plot(graph, engine='dot', filename='output/test'):
"""Possible engines: dot, neato, fdp, sfdp, twopi, circo"""
g = Graph(format='png', engine=engine)
for v in graph:
g.node(str(index(v)))
for v, w in graph.edges:
g.edge(str(index(v)), str(index(w)))
g.render(filename)
示例10: getDot
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def getDot(self, color):
dot = Graph(graph_attr = {'size':'3.5'})
for node in self.G:
if not node in color:
dot.node(node)
else:
dot.node(node, style = 'filled', color = color[node])
for n1 in self.G:
for n2 in self.G[n1]:
if n1 < n2:
dot.edge(n1, n2)
return dot
示例11: generateGraph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def generateGraph():
G = Graph(
engine = 'dot',
filename = 'Btrfs-Graph.dot',
name = 'BRTFS-Browser',
comment = 'https://github.com/Zo0MER/BRTFS-Browser.git',
graph_attr = {'rankdir': 'RL',
'charset':'utf-8',
'bgcolor':'#eeeeee',
'labelloc':'t',
'splines':'compound',
'nodesep':'0.7',
'ranksep':'5'
},
node_attr = {'fontsize': '18.0',
'shape':'box'
}
)
#node with title and hyperlink on github
G.node('meta',
label = 'Btrfs-debug-tree \nhttps://github.com/Zo0MER/BRTFS-Browser.git',
href = 'https://github.com/Zo0MER/BRTFS-Browser.git',
fontcolor = '#4d2600',
fontsize = '30.0'
)
first = inode[0]
inode.remove(inode[0])
if (inode):
#link first item ROOT_TREE_DIR INODE_ITEM, INODE_REF with all INODE_ITEM EXTEND_DATA
for pair in inode:
G.edge(''.join([str(x) for x in first]), ''.join([str(x) for x in pair]))
else:
G.node(first)
#save *.dot and others
pathout = enterPath.get()
filenameout = enterFilename.get()
if (filenameout):
filenameout = filenameout + '.gv.dot'
else:
filenameout = "btrfs-graph"
G.filename = filenameout + '.gv.dot'
G.directory = pathout
G.save()
for t in types:
G.format = t
G.render()
示例12: plot
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def plot(graph, engine='dot', filename='output/test', vertex_names={}):
"""
Possible engines: dot, neato, fdp, sfdp, twopi, circo
Vertex_names is an optional dict from vertices to strings.
"""
g = Graph(format='png', engine=engine)
def vertex_to_string(v):
return (vertex_names[v] if v in vertex_names else '') + ' ({})'.format(str(index(v)))
for v in graph:
g.node(vertex_to_string(v))
for v, w in graph.edges:
g.edge(vertex_to_string(v), vertex_to_string(w))
g.render(filename)
示例13: visualize_topics
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def visualize_topics(quora_data):
dot = Graph(comment='Topics graph', engine='sfdp')
seen_topics = set()
for document in quora_data:
question = _get_question(document)
topics = document[question]['topics']
# Iterating over topics and adding nodes for topics if necessary
for topic in topics:
if topic not in seen_topics:
dot.node(topic, label=topic)
seen_topics.add(topic)
# Iterating over topics and adding edges between topics belonging to the same question
for i in xrange(len(topics)):
for j in xrange(i+1, len(topics)):
dot.edge(topics[i], topics[j])
# topic1, topic2 in product(topics, topics):
# dot.edge(topic1, topic2)
dot = _apply_styles(dot, styles)
# print dot.source
dot.render(os.path.join('images', 'topics.gv'), view=True)
示例14: render
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def render(self, filename):
""" Renders the graph to a file.
Args:
filename (str): Filename of the map file.
"""
dot = Graph(comment='ISTravel graph', engine='fdp')
for city in self.cities:
dot.node(str(city))
ploted = []
for node in self.connections:
for edge in self.connections[node]:
if edge not in ploted:
ploted.append(edge)
dot.edge(
str(edge.nodes[0]),
str(edge.nodes[1]),
label=edge.transport[:2]
)
dot.render(filename[:filename.rfind('.')]+".gv")
示例15: create_conflicts_graph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import edge [as 别名]
def create_conflicts_graph(clauses):
dot = GGraph(comment='Conflicts graph', engine='sfdp')
for i in xrange(len(clauses)):
dot.node(str(i), label=str(i))
for i in xrange(len(clauses)):
for j in xrange(i+1, len(clauses)):
clause_i = clauses[i]
clause_j = clauses[j]
edge_labels = []
for lit in clause_i:
if -lit in clause_j:
var = abs(lit)
edge_labels.append(str(var))
if len(edge_labels) > 0:
dot.edge(str(i), str(j), label=','.join(edge_labels))
dot = _apply_styles(dot, styles)
dot.render(os.path.join('images', 'conflicts_graph.gv'), view=True)