Python pydot_ng.Node() Examples
The following are 21
code examples of pydot_ng.Node().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pydot_ng
, or try the search function
.
Example #1
Source File: test_pydot.py From pydot-ng with MIT License | 6 votes |
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
Example #2
Source File: test_pydot.py From pydot-ng with MIT License | 6 votes |
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]; } """ )
Example #3
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
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"
Example #4
Source File: utils.py From steppy with MIT License | 5 votes |
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
Example #5
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
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
Example #6
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
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
Example #7
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
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];"
Example #8
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
def test_keyword_node_id(digraph): digraph.add_node(pydot.Node("node")) assert digraph.get_nodes()[0].get_name() == "node"
Example #9
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
def test_quoted_node_id_to_string_no_attributes(digraph): digraph.add_node(pydot.Node('"node"')) assert digraph.get_nodes()[0].to_string() == '"node";'
Example #10
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
def test_quoted_node_id(digraph): digraph.add_node(pydot.Node('"node"')) assert digraph.get_nodes()[0].get_name() == '"node"'
Example #11
Source File: test_pydot.py From pydot-ng with MIT License | 5 votes |
def test_numeric_node_id(digraph): digraph.add_node(pydot.Node(1)) assert digraph.get_nodes()[0].get_name() == "1"
Example #12
Source File: utils.py From gap with MIT License | 5 votes |
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
Example #13
Source File: _dotparser.py From pydot-ng with MIT License | 5 votes |
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
Example #14
Source File: utils.py From open-solution-mapping-challenge with MIT License | 5 votes |
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
Example #15
Source File: utils.py From open-solution-toxic-comments with MIT License | 5 votes |
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
Example #16
Source File: utils.py From open-solution-data-science-bowl-2018 with MIT License | 5 votes |
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
Example #17
Source File: formatting.py From attention-lvcsr with MIT License | 5 votes |
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
Example #18
Source File: formatting.py From D-VAE with MIT License | 5 votes |
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
Example #19
Source File: _dotparser.py From pydot-ng with MIT License | 4 votes |
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], pydot.Graph): n_prev = pydot.frozendict(toks[0][0].obj_dict) else: n_prev = toks[0][0] + do_node_ports(toks[0]) if isinstance(toks[2][0], pyparsing.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(pydot.Edge(n_prev, n_next[0] + n_next_port, **attrs)) elif isinstance(toks[2][0], pydot.Graph): e.append(pydot.Edge(n_prev, pydot.frozendict(toks[2][0].obj_dict), **attrs)) elif isinstance(toks[2][0], pydot.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(pydot.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(pydot.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
Example #20
Source File: _dotparser.py From pydot-ng with MIT License | 4 votes |
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 element in toks: if isinstance(element, (pydot.Subgraph, pydot.Cluster)): add_defaults(element, defaults_graph) g.add_subgraph(element) elif isinstance(element, pydot.Node): add_defaults(element, defaults_node) g.add_node(element) elif isinstance(element, pydot.Edge): add_defaults(element, defaults_edge) g.add_edge(element) elif isinstance(element, pyparsing.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 = pydot.Node('graph', **element.attrs) g.add_node(default_graph_attrs) elif element.default_type == 'node': default_node_attrs = pydot.Node('node', **element.attrs) g.add_node(default_node_attrs) elif element.default_type == 'edge': default_edge_attrs = pydot.Node('edge', **element.attrs) g.add_node(default_edge_attrs) defaults_edge.update(element.attrs) else: raise ValueError("Unknown DefaultStatement: {0} ". format(element.default_type)) elif isinstance(element, P_AttrList): g.obj_dict['attributes'].update(element.attrs) else: raise ValueError("Unknown element statement: %r" % element)
Example #21
Source File: visualize_util.py From KerasNeuralFingerprint with MIT License | 4 votes |
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