本文整理汇总了Python中graphviz.Digraph方法的典型用法代码示例。如果您正苦于以下问题:Python graphviz.Digraph方法的具体用法?Python graphviz.Digraph怎么用?Python graphviz.Digraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphviz
的用法示例。
在下文中一共展示了graphviz.Digraph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def display(cfgs: Dict[NodeNG, ControlFlowGraph],
filename: str, view: bool = True) -> None:
graph = graphviz.Digraph(name=filename, **GRAPH_OPTIONS)
for node, cfg in cfgs.items():
if isinstance(node, astroid.Module):
subgraph_label = '__main__'
elif isinstance(node, astroid.FunctionDef):
subgraph_label = node.name
else:
continue
with graph.subgraph(name=f'cluster_{id(node)}') as c:
visited = set()
_visit(cfg.start, c, visited)
for block in cfg.unreachable_blocks:
_visit(block, c, visited)
c.attr(label=subgraph_label)
graph.render(filename, view=view)
示例2: _as_graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def _as_graph(self, finals: Optional[List[str]]) -> Digraph: # pragma: no cover
if Digraph is None:
raise ImportError('The graphviz package is required to draw the graph.')
graph = Digraph()
if finals is None:
patterns = [
'{}: {} with {}'.format(
self._colored_pattern(i), html.escape(str(p.expression)), self._format_constraint_set(c)
) for i, (p, l, c) in enumerate(self.patterns)
]
graph.node('patterns', '<<b>Patterns:</b><br/>\n{}>'.format('<br/>\n'.join(patterns)), {'shape': 'box'})
self._make_graph_nodes(graph, finals)
if finals is None:
constraints = [
'{}: {} for {}'.format(self._colored_constraint(i), html.escape(str(c)), self._format_pattern_set(p))
for i, (c, p) in enumerate(self.constraints)
]
graph.node(
'constraints', '<<b>Constraints:</b><br/>\n{}>'.format('<br/>\n'.join(constraints)), {'shape': 'box'}
)
self._make_graph_edges(graph)
return graph
示例3: GraphViz
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def GraphViz(node):
d = Graph(node)
from graphviz import Digraph
dot = Digraph("Graph", strict=False)
dot.format = 'png'
def rec(nodes, parent):
for d in nodes:
if not isinstance(d, dict):
dot.node(d, shape=d._graphvizshape)
dot.edge(d, parent)
else:
for k in d:
dot.node(k._name, shape=k._graphvizshape)
rec(d[k], k)
dot.edge(k._name, parent._name)
for k in d:
dot.node(k._name, shape=k._graphvizshape)
rec(d[k], k)
return dot
示例4: _visit
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def _visit(block: CFGBlock,
graph: graphviz.Digraph, visited: Set[int]) -> None:
node_id = f'{graph.name}_{block.id}'
if node_id in visited:
return
label = '\n'.join([s.as_string() for s in block.statements]) + '\n'
# Need to escape backslashes explicitly.
label = label.replace('\\', '\\\\')
# \l is used for left alignment.
label = label.replace('\n', '\\l')
fill_color = 'grey93' if not block.reachable else 'white'
graph.node(node_id, label=label, fillcolor=fill_color, style='filled')
visited.add(node_id)
for edge in block.successors:
graph.edge(node_id, f'{graph.name}_{edge.target.id}')
_visit(edge.target, graph, visited)
示例5: render
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def render(self, path, view):
if path is None:
path = os.path.join("trees", "{:%Y-%m-%d %H:%M:%S}.gv".format(datetime.now()))
with TemporaryDirectory() as self.tempdir:
g = Digraph(
format="png",
graph_attr={"splines": "ortho"},
node_attr={"shape": "plaintext", "labelloc": "b"},
)
for node in self.tree:
image = self.bar_chart(node)
g.node(str(node.node_id), image=image)
if node.parent is not None:
edge_label = " ({}) \n ".format(', '.join(map(str, node.choices)))
g.edge(str(node.parent), str(node.node_id), xlabel=edge_label)
g.render(path, view=view)
示例6: disp_tree
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def disp_tree(trees):
graph = Digraph()
count = 0
def add(tree, count):
if not tree:
return count
root = count
graph.node(str(root), label=tree[0])
for subtree in tree[1:]:
if subtree:
count += 1
graph.edge(str(root), str(count))
count = add(subtree, count)
return count
for tree in trees:
count = add(tree, count) + 1
graph.render('tree-rep.gv', view=True)
示例7: __init__
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def __init__(self, **kwargs):
super(ExVizPass, self).__init__()
self.show_axes = kwargs.pop('show_axes', True)
self.show_all_metadata = kwargs.pop('show_all_metadata', True)
self.subgraph_attr = kwargs.pop('subgraph_attr', None)
self.exops_with_nodes = set()
self.exops_without_nodes = set()
self.filename = kwargs.pop('filename', 'Digraph')
self.view = kwargs.pop('view', True)
self.cleanup = kwargs.pop('cleanup', True)
self.show_tensors = kwargs.pop('show_tensors', False)
output_directory = kwargs.pop('output_directory', '.')
if self.view:
if output_directory is None:
output_directory = tempfile.mkdtemp()
self.output_directory = output_directory
示例8: begin_pass
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def begin_pass(self, filename=None, **kwargs):
super(ExVizPass, self).begin_pass(**kwargs)
try:
import graphviz
except ImportError:
raise ImportError("You tried to use the ShowGraph transformer pass but did "
"not have the python graphviz library installed")
if filename is None:
filename = self.filename
self.exops_with_nodes = set()
self.exops_without_nodes = set()
self.tensors_with_nodes = set()
self.tensors_without_nodes = set()
# Get all ops from this set
self.graph = graphviz.Digraph(name=filename,
# node_attr={'shape': 'box', 'style': 'rounded'},
graph_attr={'nodesep': '.5',
'ranksep': '.5'})
示例9: to_dot
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def to_dot(self):
"""Produces a ball and stick graph of this state machine.
Returns
-------
`graphviz.Digraph`
A ball and stick visualization of this state machine.
"""
from graphviz import Digraph
dot = Digraph(format='png')
for state in self.states:
if isinstance(state, TransientState):
dot.node(state.state_id, style='dashed')
else:
dot.node(state.state_id)
for transition in state.transition_set:
dot.edge(state.state_id, transition.output_state.state_id, transition.name)
return dot
示例10: main
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def main(self,new_url,api_doc,check_commit):
redis_connection = RedisProxy()
redis_con = redis_connection.get_connection()
self.url = new_url
self.redis_graph = Graph("apigraph", redis_con)
print("loading... of graph")
self.get_endpoints(api_doc, redis_con)
if check_commit:
print("commiting")
self.redis_graph.commit()
# creating whole the graph in redis
print("done!!!!")
# uncomment below 2 lines for getting nodes for whole graph
# for node in self.redis_graph.nodes.values():
# print("\n", node.alias)
# uncomment the below lines for show the graph stored in redis
# g = Digraph('redis_graph', filename='hydra_graph.gv')
# using graphviz for visualization of graph stored in redis
# for edge in self.redis_graph.edges:
# g.edge(edge.src_node.alias, edge.dest_node.alias)
# g.view()
# see the graph generated by graphviz
示例11: enable_debugging
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def enable_debugging():
from graphviz import Digraph
global debugging_enabled, notification_graph_to_render, dot_node_sequence_number, existing_dot_nodes_to_colors
global nodes, edges
existing_dot_nodes_to_colors = dict()
debugging_enabled = True
# does not work as all edges with the same source and endpoint are merged
# dot_graph = Digraph(comment='Our fancy debugging graph', graph_attr={"concentrate": "true"})
# does not change anything
# dot_graph = Digraph(comment='Our fancy debugging graph', graph_attr={"labelfloat": "true"})
# "ortho" does not work for all engines, for others it does not do anything
# dot_graph = Digraph(comment='Our fancy debugging graph', graph_attr={"splines": "compound"})
# dot_graph = Digraph(comment='Our fancy debugging graph', graph_attr={"splines": "compound", "overlap": "false"})
notification_graph_to_render = Digraph(name='notification_graph_to_render')
dot_node_sequence_number = 0
nodes = {}
edges = OrderedDict()
示例12: show_graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def show_graph(self):
g = Digraph("Automata Graph", filename=tempfile.mktemp(), format='png')
g.attr('node', label="")
for n in self.states:
string = Automata.stringify_node(n)
if n in self.accepting_states and n != self.initial_state:
g.node(string, string, shape='doublecircle')
elif n not in self.accepting_states and n == self.initial_state:
g.node(string, string, shape='octagon')
elif n in self.accepting_states and n == self.initial_state:
g.node(string, string, shape='doubleoctagon')
else:
g.node(string, string, shape='circle')
for s, transitions in self.transitions.items():
for d, t in transitions.items():
g.edge(Automata.stringify_node(s),
Automata.stringify_node(d),
str(t).replace('\\', '\\\\'))
g.view(cleanup=True)
示例13: to_dot
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def to_dot(self, arch):
dot = graphviz.Digraph()
for node in self.nodes.values():
node_desc = "%s\n[forward_compute_time=%.3f,backward_compute_time=%.3f,activation_size=%s,parameter_size=%.1f]" % (
node.node_desc, node.forward_compute_time, node.backward_compute_time,
node.activation_size, node.parameter_size)
if node.stage_id is not None:
color = self._colors[node.stage_id % len(self._colors)]
dot.node(node.node_id, node_desc,
color=color, style='filled')
else:
dot.node(node.node_id, node_desc)
for node in self.nodes.values():
if node.node_id not in self.edges:
continue
for out_node in self.edges[node.node_id]:
dot.edge(node.node_id, out_node.node_id)
dot.render(arch)
示例14: create_graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def create_graph():
"""Create graph of relationships between Turbinia jobs and evidence.
Returns:
Instance of graphviz.dot.Digraph
"""
dot = graphviz.Digraph(comment='Turbinia Evidence graph', format='png')
for _, job in jobs_manager.JobsManager.GetJobs():
dot.node(job.NAME)
for evidence in job.evidence_input:
dot.node(evidence.__name__, shape='box')
dot.edge(evidence.__name__, job.NAME)
for evidence in job.evidence_output:
dot.node(evidence.__name__, shape='box')
dot.edge(job.NAME, evidence.__name__)
return dot
示例15: visualize
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Digraph [as 别名]
def visualize(self):
"""Creates a dot graph. Can be visualized in colab directly."""
num_vertices = np.shape(self.matrix)[0]
try:
import graphviz
g = graphviz.Digraph()
g.node(str(0), 'input')
for v in range(1, num_vertices - 1):
g.node(str(v), self.ops[v])
g.node(str(num_vertices - 1), 'output')
for src in range(num_vertices - 1):
for dst in range(src + 1, num_vertices):
if self.matrix[src, dst]:
g.edge(str(src), str(dst))
return g
except ImportError as e:
print(e)