本文整理汇总了Python中pydot_ng.Node方法的典型用法代码示例。如果您正苦于以下问题:Python pydot_ng.Node方法的具体用法?Python pydot_ng.Node怎么用?Python pydot_ng.Node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydot_ng
的用法示例。
在下文中一共展示了pydot_ng.Node方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_simple_graph_with_node
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_create_simple_graph_with_node():
graph = pydot.Dot(graph_type="digraph")
node = pydot.Node("legend")
node.set("shape", "box")
node.set("label", "mine")
graph.add_node(node)
assert graph.to_string() == dedent(
"""\
digraph G {
legend [label=mine, shape=box];
}
"""
)
示例2: test_unicode_ids
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_unicode_ids():
node1 = '"aánñoöüé€"'
node2 = '"îôø®çßΩ"'
graph = pydot.Dot()
graph.set_charset("latin1")
graph.add_node(pydot.Node(node1))
graph.add_node(pydot.Node(node2))
graph.add_edge(pydot.Edge(node1, node2))
assert graph.get_node(node1)[0].get_name() == node1
assert graph.get_node(node2)[0].get_name() == node2
assert graph.get_edges()[0].get_source() == node1
assert graph.get_edges()[0].get_destination() == node2
graph2 = pydot.graph_from_dot_data(graph.to_string())
assert graph2.get_node(node1)[0].get_name() == node1
assert graph2.get_node(node2)[0].get_name() == node2
assert graph2.get_edges()[0].get_source() == node1
assert graph2.get_edges()[0].get_destination() == node2
示例3: _create_graph
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def _create_graph(structure_dict):
"""Creates pydot graph from the pipeline structure dict.
Args:
structure_dict (dict): dict returned by step.upstream_structure
Returns:
graph (pydot.Dot): object representing upstream pipeline structure (with regard to the current Step).
"""
graph = pydot.Dot()
for node in structure_dict['nodes']:
graph.add_node(pydot.Node(node))
for node1, node2 in structure_dict['edges']:
graph.add_edge(pydot.Edge(node1, node2))
return graph
示例4: dict_to_pdnode
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def dict_to_pdnode(d):
"""Create pydot node from dict."""
e = dict()
for k, v in iteritems(d):
if v is not None:
if isinstance(v, list):
v = '\t'.join([str(x) for x in v])
else:
v = str(v)
v = str(v)
v = v.replace('"', '\'')
e[k] = v
pynode = pd.Node(**e)
return pynode
示例5: create_graph
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def create_graph(graph_info):
dot = pydot.Dot()
for node in graph_info['nodes']:
dot.add_node(pydot.Node(node))
for node1, node2 in graph_info['edges']:
dot.add_edge(pydot.Edge(node1, node2))
return dot
示例6: push_node_stmt
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def push_node_stmt(s, loc, toks):
if len(toks) == 2:
attrs = toks[1].attrs
else:
attrs = {}
node_name = toks[0]
if isinstance(node_name, list) or isinstance(node_name, tuple):
if len(node_name) > 0:
node_name = node_name[0]
n = pydot.Node(str(node_name), **attrs)
return n
示例7: test_node_style
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_node_style():
node = pydot.Node("mynode")
assert node.get_style() is None
node.add_style("abc")
assert node.get_style() == "abc"
node.add_style("def")
assert node.get_style() == "abc,def"
node.add_style("ghi")
assert node.get_style() == "abc,def,ghi"
示例8: test_numeric_node_id
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_numeric_node_id(digraph):
digraph.add_node(pydot.Node(1))
assert digraph.get_nodes()[0].get_name() == "1"
示例9: test_quoted_node_id
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_quoted_node_id(digraph):
digraph.add_node(pydot.Node('"node"'))
assert digraph.get_nodes()[0].get_name() == '"node"'
示例10: test_quoted_node_id_to_string_no_attributes
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_quoted_node_id_to_string_no_attributes(digraph):
digraph.add_node(pydot.Node('"node"'))
assert digraph.get_nodes()[0].to_string() == '"node";'
示例11: test_keyword_node_id
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_keyword_node_id(digraph):
digraph.add_node(pydot.Node("node"))
assert digraph.get_nodes()[0].get_name() == "node"
示例12: test_keyword_node_id_to_string_with_attributes
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_keyword_node_id_to_string_with_attributes(digraph):
digraph.add_node(pydot.Node("node", shape="box"))
assert digraph.get_nodes()[0].to_string() == "node [shape=box];"
示例13: test_names_of_a_thousand_nodes
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_names_of_a_thousand_nodes(digraph):
names = set(["node_%05d" % i for i in xrange(10 ** 4)])
for name in names:
digraph.add_node(pydot.Node(name, label=name))
assert set([n.get_name() for n in digraph.get_nodes()]) == names
示例14: test_quoting
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def test_quoting():
import string
g = pydot.Dot()
g.add_node(pydot.Node("test", label=string.printable))
data = g.create(format="jpe")
assert len(data) > 0
示例15: model_to_dot
# 需要导入模块: import pydot_ng [as 别名]
# 或者: from pydot_ng import Node [as 别名]
def model_to_dot(model, show_shapes=False, show_layer_names=True):
dot = pydot.Dot()
dot.set('rankdir', 'TB')
dot.set('concentrate', True)
dot.set_node_defaults(shape='record')
if model.__class__.__name__ == 'Sequential':
if not model.built:
model.build()
model = model.model
layers = model.layers
# first, populate the nodes of the graph
for layer in layers:
layer_id = str(id(layer))
if show_layer_names:
label = str(layer.name) + ' (' + layer.__class__.__name__ + ')'
else:
label = layer.__class__.__name__
if show_shapes:
# Build the label that will actually contain a table with the
# input/output
try:
outputlabels = str(layer.output_shape)
except:
outputlabels = 'multiple'
if hasattr(layer, 'input_shape'):
inputlabels = str(layer.input_shape)
elif hasattr(layer, 'input_shapes'):
inputlabels = ', '.join(
[str(ishape) for ishape in layer.input_shapes])
else:
inputlabels = 'multiple'
label = '%s\n|{input:|output:}|{{%s}|{%s}}' % (label, inputlabels, outputlabels)
node = pydot.Node(layer_id, label=label)
dot.add_node(node)
# second, add the edges
for layer in layers:
layer_id = str(id(layer))
for i, node in enumerate(layer.inbound_nodes):
node_key = layer.name + '_ib-' + str(i)
if node_key in model.container_nodes:
# add edges
for inbound_layer in node.inbound_layers:
inbound_layer_id = str(id(inbound_layer))
layer_id = str(id(layer))
dot.add_edge(pydot.Edge(inbound_layer_id, layer_id))
return dot