本文整理汇总了Python中pydot.Dot.write_png方法的典型用法代码示例。如果您正苦于以下问题:Python Dot.write_png方法的具体用法?Python Dot.write_png怎么用?Python Dot.write_png使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydot.Dot
的用法示例。
在下文中一共展示了Dot.write_png方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def handle(self, filename=None, **options):
try:
from pydot import Dot, Edge, Node
except ImportError:
raise CommandError("need pydot python module ( apt-get install python-pydot )")
graph = Dot()
for status, description in STATUS_CHOICES:
graph.add_node(Node(
'status-%s' % status,
label='"%s (%s)"' %
(description.encode('utf-8'), status))
)
from sadiki.core.workflow import workflow
for transition_index in workflow.available_transitions():
transition = workflow.get_transition_by_index(transition_index)
graph.add_edge(Edge(
'status-%s'% transition.src,
'status-%s' % transition.dst,
label='"%s (%s)"' % (transition.comment.encode('utf-8'), transition.index),
style='solid' if transition.required_permissions else 'dashed',
))
if filename:
graph.write_png(filename)
else:
print graph.to_string()
示例2: plot_state
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def plot_state(self, boxes, deltas, name = '', outdir = None):
""" Make a graph of a given state """
graph = Dot(graph_type='digraph', fontname="Verdana", size="10, 5", fixedsize= True)
i_box = 0
for box in boxes:
textcolor = 'white' if sum( [ self.color_chars.index(col) for col in self.plots_conf[box]['color'].split('#')[1] ] ) < 35 else 'black'
node_box = Node(box, style="filled", label = '<<font POINT-SIZE="10" color="'+textcolor+'">'+box+'<br/> '+
"%.7f" % round(deltas[i_box], 7)+'</font>>',
fillcolor = self.plots_conf[box]['color'], shape = self.plots_conf[box]['shape'])
i_box += 1
graph.add_node(node_box)
for box_from, boxes_to in self.Flux.iteritems():
for box_to, flux in boxes_to.iteritems():
if flux !=0:
if flux > 0:
edge = Edge(box_from, box_to, label = '<<font POINT-SIZE="10">'+str(flux)+'</font>>')
elif flux < 0:
edge = Edge(box_to, box_from, label = '<<font POINT-SIZE="10">'+str(flux)+'</font>>')
graph.add_edge(edge)
if outdir is None:
outdir = self.result_dir
outfile = outdir+'/state'+name+'.png'
graph.write_png(outfile)
logger.info('State has been saved to '+set_style(outfile, 'emph'))
示例3: visualize
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def visualize(graph, filename="graph.png", include_args=True, transitive=False):
data = to_graphviz(graph, transitive)
dot = Dot(graph_type="digraph")
for node in data["nodes"]:
fmt = format_edge(graph, node) if include_args else node
dot.add_node(Node(node, label=fmt))
for a, b in data["edges"]:
dot.add_edge(Edge(a, b))
dot.write_png(filename)
示例4: draw
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def draw(self, name, dname, draw_branches=True):
from pydot import Dot, Edge
g = Dot()
g.set_node_defaults(color='lightgray', style='filled', shape='box',
fontname='Courier', fontsize='10')
for node in sorted(self.nodes, key=lambda x: x.num):
if draw_branches and node.type.is_cond:
g.add_edge(Edge(str(node), str(node.true), color='green'))
g.add_edge(Edge(str(node), str(node.false), color='red'))
else:
for suc in self.sucs(node):
g.add_edge(Edge(str(node), str(suc), color='blue'))
g.write_png('%s/%s.png' % (dname, name))
示例5: draw
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def draw(self, name, dname, draw_branches=True):
from pydot import Dot, Edge
g = Dot()
g.set_node_defaults(color="lightgray", style="filled", shape="box", fontname="Courier", fontsize="10")
for node in sorted(self.nodes, key=lambda x: x.num):
if draw_branches and node.type.is_cond:
g.add_edge(Edge(str(node), str(node.true), color="green"))
g.add_edge(Edge(str(node), str(node.false), color="red"))
else:
for suc in self.sucs(node):
g.add_edge(Edge(str(node), str(suc), color="blue"))
for except_node in self.catch_edges.get(node, []):
g.add_edge(Edge(str(node), str(except_node), color="black", style="dashed"))
g.write_png("%s/%s.png" % (dname, name))
示例6: process_plan
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def process_plan(filename, plan):
graph = Dot()
teams = fetch_teams()
nodes = make_nodes(plan, teams)
for team_node in nodes:
graph.add_node(nodes[team_node])
for team in plan:
edges = graph_way(team, plan[team], nodes)
for edge in edges:
graph.add_edge(edge)
graph.set_prog("circo")
graph.write_png(filename)
示例7: draw
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def draw(self, prob, targetFile):
# Do the graphing stuff here...
# Root graph
g = Dot(graph_type="digraph", nodesep=2, overlap=False)
#g.set_edge_defaults(weight="0", minlen="10")
# Organise by adding constraints (adds edges too)
for constr in prob.constrs:
# Node for constraint
constrNode = Node(constr.name, shape="ellipse", style="filled", fillcolor = "#aaaaff")
constrNode.set_label(constr.name + ": " + constr.getTextFormula())
g.add_node(constrNode)
# Associated expressions
for expr in constr.exprs:
self.addNodesForChildren(g, expr, constr)
# Finally, render
#g.write_png("problem_structure.png", prog="dot")
g.write_png(targetFile, prog="neato")
示例8: render_state_diagram
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def render_state_diagram(C_M, S_M, filename, depth=None):
tot_M = C_M + S_M
if depth:
reachable_states = find_reachable_states(tot_M, len(tot_M) - 1, depth)
reachable_states.add(len(tot_M) - 1)
else:
reachable_states = range(len(tot_M))
graph = Dot(graph_type="digraph", rankdir="LR")
nodes = [Node(str(i), shape="circle") for i in range(len(tot_M) + 1)]
nodes[-2].set_shape("point")
nodes[-1].set_shape("doublecircle")
for i in reachable_states:
graph.add_node(nodes[i])
graph.add_node(nodes[-1])
def _render_edges(M, color, end_state):
for i in reachable_states:
row_sum = sum(tot_M[i])
col_sum = sum(tot_M[:, i])
if not end_state:
for j in reachable_states:
elem = M[i, j]
if elem > 0:
if col_sum > 0:
prob = elem / col_sum
else:
prob = elem / row_sum
edge = Edge(nodes[i], nodes[j], label="%.2f" % prob, color=color)
graph.add_edge(edge)
else:
if row_sum < col_sum:
prob = (col_sum - row_sum) / col_sum
edge = Edge(nodes[i], nodes[-1], label="%.2f" % prob, color=color)
graph.add_edge(edge)
_render_edges(C_M, "blue", False)
_render_edges(S_M, "red", False)
_render_edges(None, "black", True)
graph.write_png(filename)
示例9: process_plan
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def process_plan(filename, plan, names=True, with_dist=False, with_label=False):
graph = Dot(overlap="false", splines="true", esep=.2)
teams = fetch_teams()
distances = fetch_distances()
nodes = make_nodes(plan, teams, names)
for team_node in nodes:
graph.add_node(nodes[team_node])
for team in plan:
edges = graph_way(team, plan[team], nodes, distances, with_dist, with_label)
for edge in edges:
graph.add_edge(edge)
if with_dist:
graph.write_png(filename, prog="neato")
else:
graph.write_png(filename, prog="dot")
示例10: create_graph
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def create_graph(self, png_path):
from pydot import Dot, Edge, Node
graph = Dot(graph_type='digraph')
graph_nodes = {}
graph_edges = {}
done = set()
def add_node(node, expanded=False, chosen=False, in_fringe=False,
in_successors=False):
node_id = id(node)
if node_id not in graph_nodes:
label = node.state_representation()
if hasattr(node, 'cost'):
label += '\nCost: %s' % node.cost
if hasattr(node, 'heuristic'):
label += '\nHeuristic: %s' % node.heuristic
if hasattr(node, 'value'):
label += '\nValue: %s' % node.value
new_g_node = Node(node_id,
label=label,
style='filled',
shape='circle',
fillcolor='#ffffff',
fontsize=self.font_size)
graph_nodes[node_id] = new_g_node
g_node = graph_nodes[node_id]
if expanded or chosen:
g_node.set_fillcolor(self.fringe_color)
if in_fringe:
g_node.set_color(self.fringe_color)
g_node.set_penwidth(3)
if in_successors:
g_node.set_color(self.successor_color)
g_node.set_fontcolor(self.successor_color)
return g_node
def add_edge_to_parent(node, is_successor=False, parent=None):
if parent is None:
parent = node.parent
g_node = add_node(node, in_successors=is_successor)
g_parent_node = add_node(parent)
edge = Edge(g_parent_node,
g_node,
label=node.action_representation(),
fontsize=self.font_size)
if is_successor:
edge.set_color(self.successor_color)
edge.set_labelfontcolor(self.successor_color)
graph_edges[id(node), id(parent)] = edge
if self.last_event == 'chosen_node':
add_node(self.last_chosen, chosen=True)
if self.last_event == 'expanded':
for node, successors in zip(self.last_expandeds,
self.last_successors):
add_node(node, expanded=True)
for successor_node in successors:
add_edge_to_parent(successor_node,
is_successor=True,
parent=node)
for node in self.current_fringe:
add_node(node, in_fringe=True)
while node is not None and node not in done:
if node.parent is not None:
add_edge_to_parent(node)
else:
add_node(node)
done.add(node)
node = node.parent
for node_id in sorted(graph_nodes.keys()):
graph.add_node(graph_nodes[node_id])
for node_id, parent_id in sorted(graph_edges.keys()):
graph.add_edge(graph_edges[node_id, parent_id])
graph.write_png(png_path)
示例11: visualize
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def visualize(graph, filename="graph.png", include_args=True, transitive=False):
dep_data = to_graphviz(graph, transitive)
dot = Dot(graph_type="digraph")
draw_graph(dot, graph, dep_data, include_args)
dot.write_png(filename)
示例12: make_graph
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
def make_graph(self):
def lookup(email):
return self.email_lookup.get(email, email) + '\n H=' + ("%.0e" % self.hub.get(email, 0.0)) + ', A=' + ("%.0e" % self.auth.get(email, 0.0))
highest_hub = max(self.hub.get(e, 0.0) for e in self.emails)
highest_auth = max(self.auth.get(e, 0.0) for e in self.emails)
highest_hubauth = max(highest_hub, highest_auth)
def mean(s): return sum(s) * 1.0 / len(s)
def std_dev(mean_v, s): return math.sqrt(mean(map(lambda x: (x - mean_v)**2, s)))
mean_hub = mean(self.hub.values())
mean_auth = mean(self.auth.values())
def colour(email):
def to_hex(score):
return hex(int(score))[2:].zfill(2)
auth_score = ((self.auth.get(email, 0.0) / highest_auth) * 255.0)
hub_score = ((self.hub.get(email, 0.0) / highest_hub) * 255.0)
return '#' + to_hex(255.0 - auth_score) + '00' + to_hex(255.0 - hub_score)
graph = Dot(graph_type='digraph', simplify=True, suppress_disconnected=True)
mean_pr = mean(self.pr.values())
people = (Node(lookup(e), shape='record', color=colour(e), fontsize=5.0 + (5.0 * (self.pr[e] / mean_pr))) for e in self.emails)
for node in people:
graph.add_node(node)
num_emails = []
for sender in self.outgoing.keys():
for receiver in self.outgoing[sender].keys():
num_emails.append(len(self.outgoing[sender][receiver]))
mean_emails = mean(num_emails)
email_std_dev = std_dev(mean_emails, num_emails)
p_ranks = []
for sender in self.outgoing.keys():
for receiver in self.outgoing[sender].keys():
p_ranks.append(self.e_reader.phoenix_rank(self.outgoing[sender][receiver] + self.outgoing.get(receiver, {}).get(sender, [])))
mean_p_rank = mean(p_ranks)
p_rank_std_dev = std_dev(mean_p_rank, p_ranks)
links = []
for sender in self.outgoing.keys():
for receiver in self.outgoing[sender].keys():
count = len(self.outgoing[sender][receiver])
prop = float(count) / mean_emails
if count >= mean_emails + (email_std_dev / 4):
#content = ' '.join(self.e_reader.highest_weighted(set(self.outgoing[sender][receiver])))
phoenix_rank = self.e_reader.phoenix_rank(self.outgoing[sender][receiver] + self.outgoing.get(receiver, {}).get(sender, []))
if phoenix_rank >= (p_rank_std_dev / 3) + mean_p_rank:
color = "#ff0000"
else:
color = "#000000"
links.append(Edge(lookup(sender), lookup(receiver), color=color, penwidth=((0.7 + (prop / 4.0))/ 2.0), weight=prop))
for edge in links: graph.add_edge(edge)
graph.write_png('./graph.png')
graph.write('graph.dot', format='raw', prog='dot')
示例13: Dot
# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import write_png [as 别名]
from pyd.atm_state import *
from pydot import Dot, Node, Edge
file = "/tmp/atm_state_machine.png"
dot = Dot(graph_type="digraph", comment="Atm State Machine")
nodes = {}
graph = {}
for name, state in State.get_subclasses_dict().iteritems():
nodes.setdefault(name, Node(name))
for name, state in State.get_subclasses_dict().iteritems():
for event, state in state.get_valid_events():
edge = Edge(nodes.get(name), nodes.get(state))
edge.set_label(event)
graph.setdefault(name, []).append(edge)
for name, edges in graph.iteritems():
for edge in edges:
dot.add_node(nodes.get(name))
dot.add_edge(edge)
dot.write_png(file)