本文整理汇总了Python中pydotplus.Edge方法的典型用法代码示例。如果您正苦于以下问题:Python pydotplus.Edge方法的具体用法?Python pydotplus.Edge怎么用?Python pydotplus.Edge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydotplus
的用法示例。
在下文中一共展示了pydotplus.Edge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode_ids
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Edge [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 Edge [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: add_outgoing_edge
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Edge [as 别名]
def add_outgoing_edge(self, node, weight):
edge = Edge(self, node, weight)
self.outgoing_edges.append(edge)
return edge
示例4: __repr__
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Edge [as 别名]
def __repr__(self):
return 'Edge(node_0: {}, node_1:{}, weight:{})'.format(self.node_0.address_id, self.node_1.address_id, self.weight)
示例5: test_graph_pickling
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Edge [as 别名]
def test_graph_pickling(self):
import pickle
g = pydotplus.Graph()
s = pydotplus.Subgraph("foo")
g.add_subgraph(s)
g.add_edge(pydotplus.Edge('A', 'B'))
g.add_edge(pydotplus.Edge('A', 'C'))
g.add_edge(pydotplus.Edge(('D', 'E')))
g.add_node(pydotplus.Node('node!'))
self.assertEqual(type(pickle.dumps(g)), bytes)
示例6: add_elements
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Edge [as 别名]
def add_elements(g, toks,
defaults_graph=None,
defaults_node=None,
defaults_edge=None):
if defaults_graph is None:
defaults_graph = {}
if defaults_node is None:
defaults_node = {}
if defaults_edge is None:
defaults_edge = {}
for elm_idx, element in enumerate(toks):
if isinstance(element, (pydotplus.Subgraph, pydotplus.Cluster)):
add_defaults(element, defaults_graph)
g.add_subgraph(element)
elif isinstance(element, pydotplus.Node):
add_defaults(element, defaults_node)
g.add_node(element)
elif isinstance(element, pydotplus.Edge):
add_defaults(element, defaults_edge)
g.add_edge(element)
elif isinstance(element, ParseResults):
for e in element:
add_elements(
g, [e], defaults_graph, defaults_node, defaults_edge
)
elif isinstance(element, DefaultStatement):
if element.default_type == 'graph':
default_graph_attrs = pydotplus.Node('graph', **element.attrs)
g.add_node(default_graph_attrs)
elif element.default_type == 'node':
default_node_attrs = pydotplus.Node('node', **element.attrs)
g.add_node(default_node_attrs)
elif element.default_type == 'edge':
default_edge_attrs = pydotplus.Node('edge', **element.attrs)
g.add_node(default_edge_attrs)
defaults_edge.update(element.attrs)
else:
raise ValueError(
"Unknown DefaultStatement: %s " % element.default_type
)
elif isinstance(element, P_AttrList):
g.obj_dict['attributes'].update(element.attrs)
else:
raise ValueError("Unknown element statement: %r" % element)
示例7: push_edge_stmt
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Edge [as 别名]
def push_edge_stmt(str, loc, toks):
tok_attrs = [a for a in toks if isinstance(a, P_AttrList)]
attrs = {}
for a in tok_attrs:
attrs.update(a.attrs)
e = []
if isinstance(toks[0][0], pydotplus.Graph):
n_prev = pydotplus.frozendict(toks[0][0].obj_dict)
else:
n_prev = toks[0][0] + do_node_ports(toks[0])
if isinstance(toks[2][0], ParseResults):
n_next_list = [[n.get_name()] for n in toks[2][0]]
for n_next in [n for n in n_next_list]:
n_next_port = do_node_ports(n_next)
e.append(pydotplus.Edge(n_prev, n_next[0] + n_next_port, **attrs))
elif isinstance(toks[2][0], pydotplus.Graph):
e.append(
pydotplus.Edge(
n_prev,
pydotplus.frozendict(toks[2][0].obj_dict),
**attrs
)
)
elif isinstance(toks[2][0], pydotplus.Node):
node = toks[2][0]
if node.get_port() is not None:
name_port = node.get_name() + ":" + node.get_port()
else:
name_port = node.get_name()
e.append(pydotplus.Edge(n_prev, name_port, **attrs))
elif isinstance(toks[2][0], type('')):
for n_next in [n for n in tuple(toks)[2::2]]:
if isinstance(n_next, P_AttrList) or \
not isinstance(n_next[0], type('')):
continue
n_next_port = do_node_ports(n_next)
e.append(pydotplus.Edge(n_prev, n_next[0] + n_next_port, **attrs))
n_prev = n_next[0] + n_next_port
else:
# UNEXPECTED EDGE TYPE
pass
return e
示例8: to_pydot
# 需要导入模块: import pydotplus [as 别名]
# 或者: from pydotplus import Edge [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