本文整理汇总了Python中pydotplus.Dot方法的典型用法代码示例。如果您正苦于以下问题:Python pydotplus.Dot方法的具体用法?Python pydotplus.Dot怎么用?Python pydotplus.Dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydotplus
的用法示例。
在下文中一共展示了pydotplus.Dot方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode_ids
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def test_unicode_ids(self):
node1 = '"aánñoöüé€"'
node2 = '"îôø®çßΩ"'
g = pydotplus.Dot()
g.set_charset('latin1')
g.add_node(pydotplus.Node(node1))
g.add_node(pydotplus.Node(node2))
g.add_edge(pydotplus.Edge(node1, node2))
self.assertEqual(g.get_node(node1)[0].get_name(), node1)
self.assertEqual(g.get_node(node2)[0].get_name(), node2)
self.assertEqual(g.get_edges()[0].get_source(), node1)
self.assertEqual(g.get_edges()[0].get_destination(), node2)
g2 = pydotplus.graph_from_dot_data(g.to_string())
self.assertEqual(g2.get_node(node1)[0].get_name(), node1)
self.assertEqual(g2.get_node(node2)[0].get_name(), node2)
self.assertEqual(g2.get_edges()[0].get_source(), node1)
self.assertEqual(g2.get_edges()[0].get_destination(), node2)
示例2: bpmn_diagram_to_png
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def bpmn_diagram_to_png(bpmn_diagram, file_name):
"""
Create a png picture for given diagram
:param bpmn_diagram: an instance of BPMNDiagramGraph class,
:param file_name: name of generated file.
"""
g = bpmn_diagram.diagram_graph
graph = pydotplus.Dot()
for node in g.nodes(data=True):
if node[1].get(consts.Consts.type) == consts.Consts.task:
n = pydotplus.Node(name=node[0], shape="box", style="rounded", label=node[1].get(consts.Consts.node_name))
elif node[1].get(consts.Consts.type) == consts.Consts.exclusive_gateway:
n = pydotplus.Node(name=node[0], shape="diamond", label=node[1].get(consts.Consts.node_name))
else:
n = pydotplus.Node(name=node[0], label=node[1].get(consts.Consts.node_name))
graph.add_node(n)
for edge in g.edges(data=True):
e = pydotplus.Edge(src=edge[0], dst=edge[1], label=edge[2].get(consts.Consts.name))
graph.add_edge(e)
graph.write(file_name + ".png", format='png')
示例3: _check_pydot
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def _check_pydot():
try:
# Attempt to create an image of a blank graph
# to check the pydot/graphviz installation.
pydot.Dot.create(pydot.Dot())
except Exception:
# pydot raises a generic Exception here,
# so no specific class can be caught.
raise ImportError('Failed to import pydot. You must install pydot'
' and graphviz for `pydotprint` to work.')
示例4: test_keep_graph_type
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def test_keep_graph_type(self):
g = pydotplus.Dot(graph_name='Test', graph_type='graph')
self.assertEqual(g.get_type(), 'graph')
g = pydotplus.Dot(graph_name='Test', graph_type='digraph')
self.assertEqual(g.get_type(), 'digraph')
示例5: test_create_simple_graph_with_node
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def test_create_simple_graph_with_node(self):
g = pydotplus.Dot()
g.set_type('digraph')
node = pydotplus.Node('legend')
node.set("shape", 'box')
g.add_node(node)
node.set('label', 'mine')
self.assertEqual(
g.to_string(),
'digraph G {\nlegend [label=mine, shape=box];\n}\n'
)
示例6: test_executable_not_found_exception
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def test_executable_not_found_exception(self):
paths = {'dot': 'invalid_executable_path'}
graph = pydotplus.Dot('graphname', graph_type='digraph')
graph.set_graphviz_executables(paths)
self.assertRaises(pydotplus.InvocationException, graph.create)
示例7: push_top_graph_stmt
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def push_top_graph_stmt(str, loc, toks):
attrs = {}
g = None
for element in toks:
if (isinstance(element, (ParseResults, tuple, list)) and
len(element) == 1 and isinstance(element[0], basestring)):
element = element[0]
if element == 'strict':
attrs['strict'] = True
elif element in ['graph', 'digraph']:
attrs = {}
g = pydotplus.Dot(graph_type=element, **attrs)
attrs['type'] = element
top_graphs.append(g)
elif isinstance(element, basestring):
g.set_name(element)
elif isinstance(element, pydotplus.Subgraph):
g.obj_dict['attributes'].update(element.obj_dict['attributes'])
g.obj_dict['edges'].update(element.obj_dict['edges'])
g.obj_dict['nodes'].update(element.obj_dict['nodes'])
g.obj_dict['subgraphs'].update(element.obj_dict['subgraphs'])
g.set_parent_graph(g)
elif isinstance(element, P_AttrList):
attrs.update(element.attrs)
elif isinstance(element, (ParseResults, list)):
add_elements(g, element)
else:
raise ValueError("Unknown element statement: %r " % element)
for g in top_graphs:
update_parent_graph_hierarchy(g)
if len(top_graphs) == 1:
return top_graphs[0]
return top_graphs
示例8: to_pydot
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Dot [as 别名]
def to_pydot(N, strict=True):
"""Return a pydot graph from a NetworkX graph N.
Parameters
----------
N : NetworkX graph
A graph created with NetworkX
Examples
--------
>>> K5 = nx.complete_graph(5)
>>> P = nx.nx_pydot.to_pydot(K5)
Notes
-----
"""
import pydotplus
# set Graphviz graph type
if N.is_directed():
graph_type='digraph'
else:
graph_type='graph'
strict=N.number_of_selfloops()==0 and not N.is_multigraph()
name = N.name
graph_defaults=N.graph.get('graph',{})
if name is '':
P = pydotplus.Dot('', graph_type=graph_type, strict=strict,
**graph_defaults)
else:
P = pydotplus.Dot('"%s"'%name, graph_type=graph_type, strict=strict,
**graph_defaults)
try:
P.set_node_defaults(**N.graph['node'])
except KeyError:
pass
try:
P.set_edge_defaults(**N.graph['edge'])
except KeyError:
pass
for n,nodedata in N.nodes_iter(data=True):
str_nodedata=dict((k,make_str(v)) for k,v in nodedata.items())
p=pydotplus.Node(make_str(n),**str_nodedata)
P.add_node(p)
if N.is_multigraph():
for u,v,key,edgedata in N.edges_iter(data=True,keys=True):
str_edgedata=dict((k,make_str(v)) for k,v in edgedata.items())
edge=pydotplus.Edge(make_str(u), make_str(v),
key=make_str(key), **str_edgedata)
P.add_edge(edge)
else:
for u,v,edgedata in N.edges_iter(data=True):
str_edgedata=dict((k,make_str(v)) for k,v in edgedata.items())
edge=pydotplus.Edge(make_str(u),make_str(v),**str_edgedata)
P.add_edge(edge)
return P