本文整理汇总了Python中pygraphviz.AGraph.draw方法的典型用法代码示例。如果您正苦于以下问题:Python AGraph.draw方法的具体用法?Python AGraph.draw怎么用?Python AGraph.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygraphviz.AGraph
的用法示例。
在下文中一共展示了AGraph.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def draw(self):
tree = self.to_tree()
A = AGraph(tree)
if not self.filename:
self.filename = input('Please input a filename:')
A.draw('temp/{}.jpg'.format(self.filename),
format='jpg', prog='fdp')
示例2: render
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def render(self, filename):
g = AGraph(strict=False, directed=True)
# create nodes
for frame_id, node in self.callers.items():
label = "{ %s }" % node
g.add_node(frame_id, shape='Mrecord', label=label,
fontsize=13, labelfontsize=13)
# create edges
for frame_id, node in self.callers.items():
child_nodes = []
for child_id in node.child_methods:
child_nodes.append(child_id)
g.add_edge(frame_id, child_id)
# order edges l to r
if len(child_nodes) > 1:
sg = g.add_subgraph(child_nodes, rank='same')
sg.graph_attr['rank'] = 'same'
prev_node = None
for child_node in child_nodes:
if prev_node:
sg.add_edge(prev_node, child_node, color="#ffffff")
prev_node = child_node
g.layout()
g.draw(path=filename, prog='dot')
print("callviz: rendered to %s" % filename)
self.clear()
示例3: run_graph
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def run_graph(dot):
""" Runs graphviz to see if the syntax is good. """
graph = AGraph()
graph = graph.from_string(dot)
extension = 'png'
graph.draw(path='output.png', prog='dot', format=extension)
sys.exit(0)
示例4: dot_to_graph
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def dot_to_graph(dot, output_path):
"""
Render by calling graphviz the figure on the output path.
:param dot: str with the
:param output_path:
:return:
"""
from pygraphviz import AGraph
graph = AGraph().from_string(dot)
graph.draw(path=output_path, prog='dot')
示例5: draw_workflow
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def draw_workflow(filename, workflow):
dot = AGraph(directed=True, strict=False) # (comment="Computing scheme")
for i, n in workflow.nodes.items():
dot.add_node(i, label="{0} \n {1}".format(n.foo.__name__, _format_arg_list(n.bound_args.args, None)))
for i in workflow.links:
for j in workflow.links[i]:
dot.add_edge(i, j[0], j[1].name) # , headlabel=j[1].name, labeldistance=1.8)
dot.layout(prog="dot")
dot.draw(filename)
示例6: __call__
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def __call__(self):
self.request.response.setHeader('Content-Type', 'image/svg+xml')
self.request.response.setHeader('Content-Disposition',
'inline; filename=%s.svg' % \
self.context.getId())
tfile = tempfile.NamedTemporaryFile(suffix='.svg')
gv = generate_gv(self.context)
ag = AGraph(string=gv)
ag.layout()
ag.draw(path=tfile, format='svg', prog='dot')
tfile.seek(0)
return tfile.read()
示例7: render_local
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def render_local(self, filename):
"""Renders the OBST image locally using pygraphviz."""
# Get the graph information
node_list, edge_list = self.__generate_image()
# Generate the graph
from pygraphviz import AGraph
G=AGraph(strict=True,directed=True) # Create a graph
for node in node_list:
G.add_node(node)
for edge in edge_list:
G.add_edge(edge[0], edge[1])
G.layout('dot') # Set hierarchical layout
G.draw(filename) # Save the image.
示例8: to_dot
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def to_dot(self, filename, edges):
from pygraphviz import AGraph
dot = AGraph(directed=True)
for n in edges.keys():
dot.add_node(str(n))
if lib.qcgc_arena_get_blocktype(ffi.cast("cell_t *", n)) not in [
lib.BLOCK_BLACK, lib.BLOCK_WHITE]:
node = dot.get_node(str(n))
node.attr['color'] = 'red'
for n in edges.keys():
if edges[n] is not None:
dot.add_edge(str(n), str(edges[n]))
dot.layout(prog='dot')
dot.draw(filename)
示例9: run
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def run(self):
options = self.options
filename = self.arguments[0]
if self.content:
content = u'\n'.join(self.content)
ofilename = filename + '.' + self.outputformat
else:
content = open(filename).read().decode(options.get('encoding','utf-8'))
ofilename = os.path.splitext(filename)[0] + '.' + self.outputformat
g = AGraph(string=content)
g.layout(prog='dot')
opath = os.path.join(OUTPUT_DIR, ofilename)
g.draw(opath, 'png')
self.arguments[0] = opath
return super(GraphvizBlock, self).run()
示例10: render_image
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def render_image(self, filename):
"""Renders the graph image locally using pygraphviz."""
# Create a graph
G=AGraph(directed=False)
# Add nodes
for node in self.nodes:
G.add_node(node)
# Add edges
for edge in self.edges:
G.add_edge(edge[0], edge[1], color='blue')
# Give layout and draw.
G.layout('circo')
G.draw(filename) # Save the image.
# Display the output image.
os.system("gwenview %s&" % filename)
示例11: graph
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def graph(self, filename, reachable=True):
from pygraphviz import AGraph # NOTE - LIS machines do not have pygraphviz
graph = AGraph(strict=True, directed=True)
for vertex in self.vertices.values():
for connector in vertex.connectors:
if not reachable or (vertex.reachable and connector.reachable):
graphviz_connect(graph, vertex, connector)
for connector in self.connectors.values():
for edge in connector.edges:
if not reachable or (connector.reachable and edge.reachable):
graphviz_connect(graph, connector, edge)
for edge in self.edges.values():
for _, sink_vertex in edge.mappings:
if not reachable or (edge.reachable and sink_vertex.reachable):
graphviz_connect(graph, edge, sink_vertex)
graph.draw(filename, prog='dot')
示例12: render_image
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def render_image(node_list, edge_list):
# Generate the graph
from pygraphviz import AGraph
G=AGraph(strict=False,directed=True) # Create a graph
for node in node_list:
G.add_node(node)
for edge in edge_list:
G.add_edge(edge[0], edge[1])
G.layout('dot') # Set hierarchical layout
filename = str(time())
postfix = 0
while exists(filename+str(postfix)+".png"):
postfix+=1
filename += str(postfix) + ".png"
G.draw(filename) # Save the image.
with open(filename, "rb") as handle:
return xmlrpclib.Binary(handle.read())
示例13: write_graph
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
def write_graph(probs, path):
graph = AGraph(directed=True)
next_label = 0
labels = {}
for from_state, to_states in probs.iteritems():
if from_state not in labels:
labels[from_state] = next_label
next_label += 1
for to_state in to_states:
if to_state not in labels:
labels[to_state] = next_label
next_label += 1
for label in xrange(next_label):
graph.add_node(label, fillcolor="blue", label="", style="filled")
for from_state, to_states in probs.iteritems():
for to_state, prob in to_states.iteritems():
graph.add_edge(labels[from_state], labels[to_state], label="%.2g" % prob)
# prog: neato (default), dot, twopi, circo, fdp or nop.
graph.layout()
graph.draw(path)
示例14: recalculate
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
#.........这里部分代码省略.........
relevant_teams |= circle
if len(circle) == 1:
continue
color_index, current_color = getcolor(color_index)
for team in circle:
gvcircles.add_node(asciiname(team), label = team.name, color = current_color, fontcolor = current_color)
gvfull.get_node(asciiname(team)).attr['color'] = current_color
gvfull.get_node(asciiname(team)).attr['fontcolor'] = current_color
for source, dest, weight in team_graph.edges():
if source in circle and dest in circle:
gvcircles.add_edge(asciiname(source), asciiname(dest), label = str(weight), color = current_color, fontcolor = current_color)
gvfull.get_edge(asciiname(source), asciiname(dest)).attr['color'] = current_color
gvfull.get_edge(asciiname(source), asciiname(dest)).attr['fontcolor'] = current_color
place = [[(team.normalized_jugg_diff(relevant_teams), team.name, team) for team in circle] for circle in place]
for circle in place:
circle.sort(reverse = True)
while place:
place_list.append(set())
i = 0
while i < len(place):
circle = place[i]
jd = circle[0][0]
while circle and circle[0][0] == jd:
place_list[-1].add(circle.pop(0))
if not circle:
place.remove(circle)
else:
i += 1
for same_place_set in place_list:
# tie breaker
if len(same_place_set) > 1:
# teams that everyone on this place played against
relevant_teams = team_graph.nodes()
for circ_jugg_diff, name, team in same_place_set:
opponents = set()
for game in team.games():
if game.team_1 == team:
opponents.add(game.team_2)
else:
opponents.add(game.team_1)
relevant_teams &= opponents
if len(relevant_teams) > 0:
color_index, current_color_a = getcolor(color_index)
color_index, current_color_b = getcolor(color_index)
for team in relevant_teams:
gvtiebreaker.add_node("b-" + asciiname(team), label = team.name, color = current_color_b, fontcolor = current_color_b)
for void, void, team in same_place_set:
gvtiebreaker.add_node("a-" + asciiname(team), label = team.name, color = current_color_a, fontcolor = current_color_a)
for game in team.games():
if game.team_1 == team and game.team_2 in relevant_teams:
if game.winner() == team:
gvtiebreaker.add_edge("a-" + asciiname(team), "b-" + asciiname(game.team_2), label = game.jugg_diff(), color = current_color_a, fontcolor = current_color_a)
else:
gvtiebreaker.add_edge("b-" + asciiname(game.team_2), "a-" + asciiname(team), label = game.jugg_diff(), color = current_color_b, fontcolor = current_color_b)
elif game.team_2 == team and game.team_1 in relevant_teams:
if game.winner() == team:
gvtiebreaker.add_edge("a-" + asciiname(team), "b-" + asciiname(game.team_1), label = game.jugg_diff(), color = current_color_a, fontcolor = current_color_a)
else:
gvtiebreaker.add_edge("b-" + asciiname(game.team_1), "a-" + asciiname(team), label = game.jugg_diff(), color = current_color_b, fontcolor = current_color_b)
# jugg differences against relevant teams
rel_jugg_diffs = set()
for team_tuple in same_place_set:
rel_jugg_diffs.add((team_tuple, team_tuple[2].normalized_jugg_diff(relevant_teams)))
# pop all teams, highest relevant jugg difference first
while rel_jugg_diffs:
# current maximum
max_rel_jugg_diff = None
# teams with maximum jugg difference
to_remove = None
for team_tuple, rel_jugg_diff in rel_jugg_diffs:
# new maximum
if max_rel_jugg_diff is None or rel_jugg_diff > max_rel_jugg_diff[0]:
max_rel_jugg_diff = (rel_jugg_diff, {team_tuple})
to_remove = {(team_tuple, rel_jugg_diff)}
# same as maximum
elif rel_jugg_diff == max_rel_jugg_diff[0]:
max_rel_jugg_diff[1].add(team_tuple)
to_remove.add((team_tuple, rel_jugg_diff))
# remove teams with maximum jugg difference
rel_jugg_diffs -= to_remove
# add teams to listing
for (circ_jugg_diff, name, team), rel_jugg_diff in to_remove:
RankedTeam.objects.create(place = current_place, team = team)
current_place += 1
else:
circ_jugg_diff, name, team = same_place_set.pop()
RankedTeam.objects.create(place = current_place, team = team)
current_place += 1
with tempfile.NamedTemporaryFile(suffix = ".png") as tmp:
gvfull.draw(tmp, "png", "dot")
pic = RankingPicture(user = user, image = File(tmp), title = "Full Team Graph")
pic.save()
with tempfile.NamedTemporaryFile(suffix = ".png") as tmp:
gvcircles.draw(tmp, "png", "dot")
pic = RankingPicture(user = user, image = File(tmp), title = "Circles")
pic.save()
with tempfile.NamedTemporaryFile(suffix = ".png") as tmp:
gvtiebreaker.draw(tmp, "png", "dot")
pic = RankingPicture(user = user, image = File(tmp), title = "Tie Breaker")
pic.save()
示例15: FSM
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import draw [as 别名]
if __name__ == '__main__':
M1 = FSM(G7)
M2 = FSM(G8)
D1 = M1.get_DFA()
D2 = M2.get_DFA()
args = [(M1.get_dot_data(), u"НДКА первой грамматики"),
(M2.get_dot_data(), u"НДКА второй грамматики"),
(D1.get_dot_data(), u"ДКА первой грамматики"),
(D2.get_dot_data(), u"ДКА второй грамматики")]
# threads = [Process(target=show_graph, args=a) for a in args]
# map(Process.start, threads)
# map(Process.join, threads)
from pygraphviz import AGraph
for data, name in args:
G = AGraph(data)
G.draw(name + '.png', prog='dot')
with open("test.txt") as f:
chains = f.read().replace(" ", "").split('\n')
chains1 = []
chains2 = []
chains_no_one = []
for c in chains:
if D1.check_chain(c):
chains1.append(c)
elif D2.check_chain(c):
chains2.append(c)
else:
chains_no_one.append(c)