Python pydot.Node() Examples
The following are 30
code examples of pydot.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
, or try the search function
.
Example #1
Source File: graph.py From dcc with Apache License 2.0 | 7 votes |
def draw(self, name, dname, draw_branches=True): from pydot import Dot, Edge,Node g = Dot() g.set_node_defaults(color='lightgray', style='filled', shape='box', fontname='Courier', fontsize='10') if len(self.nodes) == 1: g.add_node(Node(str(self.nodes[0]))) else: for node in sorted(self.nodes, key=lambda x: x.num): for suc in self.sucs(node): g.add_edge(Edge(str(node), str(suc), color='blue')) for except_node in self.catch_edges.get(node, []): g.add_edge(Edge(str(node), str(except_node), color='black', style='dashed')) g.write_png('%s/%s.png' % (dname, name))
Example #2
Source File: plot_hierarchy.py From semantic-embeddings with MIT License | 6 votes |
def plot_hierarchy(hierarchy, filename, class_names = None): if isinstance(hierarchy, ClassHierarchy): hierarchy = hierarchy.children graph = pydot.Dot(graph_type = 'digraph', rankdir = 'LR') nodes = {} for lbl, children in hierarchy.items(): nodes[lbl] = pydot.Node(lbl, label = lbl if class_names is None else class_names[lbl], style = 'filled', fillcolor = '#ffffff' if len(children) == 0 else '#eaeaea') for child in children: if child not in hierarchy: nodes[child] = pydot.Node(child, label = child if class_names is None else class_names[child], style = 'filled', fillcolor = '#ffffff') for node in nodes.values(): graph.add_node(node) for parent, children in hierarchy.items(): for child in children: graph.add_edge(pydot.Edge(nodes[parent], nodes[child])) graph.write_svg(filename, prog = 'dot')
Example #3
Source File: relations.py From oerplib with GNU Lesser General Public License v3.0 | 6 votes |
def _create_node(self, name, type_, tpl=None): """Generate a `pydot.Node` object. `type_` can take one of these values: ``relation``, ``m2m_table``. If a HTML `tpl` is supplied, it will be used as layout for the node. """ import pydot types = { 'relation': { 'margin': '0', 'shape': tpl and 'none' or 'record', 'label': tpl or name, }, 'm2m_table': { 'margin': '0', 'shape': tpl and 'none' or 'record', 'color': self._config['color_many2many'], 'fontcolor': self._config['color_many2many'], 'label': tpl or name, }, } return pydot.Node(name, **types[type_])
Example #4
Source File: Digraph.py From PrincetonAlgorithms with GNU General Public License v2.0 | 6 votes |
def wr_png(self, fout_png="Digraph.png", prt=sys.stdout, **kwargs): """Make a png showing a diagram of the connected components.""" import pydot # 1. Create/initialize Graph G = pydot.Dot(graph_type='digraph') # Undirected Graph # 2. Create Nodes nodes = [pydot.Node(v) for v in self.keys] # 3. Add nodes to Graph for node in nodes: G.add_node(node) # 4. Add Edges between Nodes to Graph for v, w in self.get_edges(): if v != w: # Print only edges from one node to another (not to self) G.add_edge(pydot.Edge(v, w)) # 5. Write Graph to png file G.write_png(fout_png) prt.write(" WROTE: {}\n".format(fout_png))
Example #5
Source File: BaseComp.py From PrincetonAlgorithms with GNU General Public License v2.0 | 6 votes |
def wr_png(self, fout_png="components.png", prt=sys.stdout, **kwargs): """Make a png showing a diagram of the connected components.""" import pydot label = get_png_label(self.ID, kwargs) # 1. Create/initialize Graph G = pydot.Dot(label=label, graph_type='digraph') # Directed Graph # 2. Create Nodes nodes = [pydot.Node(str(idx)) for idx in range(len(self.ID))] # 3. Add nodes to Graph for node in nodes: G.add_node(node) # 4. Add Edges between Nodes to Graph for child, parent in enumerate(self.ID): if child != parent: # Print only edges from one node to another (not to self) G.add_edge(pydot.Edge(nodes[parent], nodes[child])) # 5. Write Graph to png file G.write_png(fout_png) prt.write(" WROTE: {}\n".format(fout_png))
Example #6
Source File: Graph.py From PrincetonAlgorithms with GNU General Public License v2.0 | 6 votes |
def wr_png(self, fout_png="Graph.png", prt=sys.stdout, **kwargs): """Make a png showing a diagram of the connected components.""" import pydot # 1. create/initialize graph g = pydot.Dot(graph_type='graph') # undirected graph # 2. create nodes nodes = [pydot.Node(v) for v in self.keys] # 3. add nodes to graph for node in nodes: g.add_node(node) # 4. add edges between nodes to graph for v, w in self.get_edges(): if v != w: # print only edges from one node to another (not to self) g.add_edge(pydot.Edge(v, w)) # 5. write graph to png file g.write_png(fout_png) prt.write(" wrote: {}\n".format(fout_png))
Example #7
Source File: binary_heaps.py From PrincetonAlgorithms with GNU General Public License v2.0 | 6 votes |
def wr_png_array(bh_st, kwargs): """Given an array for a binary heap, draw tree.""" import pydot prt = sys.stdout if 'prt' not in kwargs else kwargs['prt'] fout_png = "binary_heap_{}.png".format('_'.join(str(e) for e in bh_st)) label = get_png_label(bh_st, kwargs) # 1. Create/initialize Graph G = pydot.Dot(label=label, graph_type='digraph') # Directed Graph edge_idxs = get_edges(bh_st) badcol = {c:'#fe2f4a' for p, c in edge_idxs if bh_st[p] < bh_st[c]} # 2. Create Nodes mknode = lambda i, v: pydot.Node( "{V}[{I}]".format(I=i+1, V=v), style = "filled", fillcolor = badcol.get(i, "beige")) nodes = [mknode(i,v) for i, v in enumerate(bh_st) if v is not None] # 3. Add nodes to Graph for node in nodes: G.add_node(node) # 4. Add Edges between Nodes to Graph for p, c in edge_idxs: G.add_edge(pydot.Edge(nodes[p], nodes[c])) # 5. Write Graph to png file G.write_png(fout_png) prt.write(" WROTE: {}\n".format(fout_png))
Example #8
Source File: relationship.py From relationships with MIT License | 6 votes |
def get_network(self, output): user_id = self._get_actor() try: import pydot except ImportError: raise ImportError("You need pydot library to get network functionality.") graph = pydot.Dot('network_of_user_{}'.format(user_id), graph_type='digraph') target_node = pydot.Node(user_id) for _id in self(user_id).following(): user_node = pydot.Node(_id) graph.add_edge(pydot.Edge(target_node, user_node)) for _id in self(user_id).followers(): user_node = pydot.Node(_id) graph.add_edge(pydot.Edge(user_node, target_node)) graph.write_png(output)
Example #9
Source File: node.py From boofuzz with GNU General Public License v2.0 | 6 votes |
def render_node_graphviz(self): """ Render a node suitable for use in a Pydot graph using the set internal attributes. @rtype: pydot.Node @return: Pydot object representing node """ dot_node = pydot.Node(self.id) dot_node.label = '<<font face="lucida console">%s</font>>' % self.label.rstrip("\r\n") dot_node.label = dot_node.label.replace("\\n", "<br/>") dot_node.shape = self.shape dot_node.color = "#%06x" % self.color dot_node.fillcolor = "#%06x" % self.color return dot_node
Example #10
Source File: create_call_graph.py From macke with Apache License 2.0 | 5 votes |
def create_pydot_nodes(): colors = {} tooltips = {} urls = {} for f in glob.glob(dir_name + '*_units/*.c.callee'): pattern = dir_name + '(.*)_units/(.*?)_(.*).c.callee' re_match = re.search(pattern, f) colors[re_match.group(3)], tooltips[re_match.group(3)], urls[re_match.group(3)] = get_node_decoration(re_match.group(1), re_match.group(3).split('_')[-1]) for n in nodes: if urls[n]!='': pydot_nodes[n] = pydot.Node(n, style='filled', fillcolor=colors[n], tooltip=tooltips[n], URL=urls[n]) else: pydot_nodes[n] = pydot.Node(n, style='filled', fillcolor=colors[n], tooltip=tooltips[n])
Example #11
Source File: Plots.py From pyaf with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot_hierarchy(structure , iAnnotations, name): import pydot graph = pydot.Dot(graph_type='graph', rankdir='LR', fontsize="12.0"); graph.set_node_defaults(shape='record') lLevelsReversed = sorted(structure.keys(), reverse=True); for level in lLevelsReversed: color = '#%02x%02x%02x' % (255, 255, 127 + int(128 * (1.0 - (level + 1.0) / len(lLevelsReversed)))); for col in structure[level].keys(): lLabel = col if iAnnotations is None else str(iAnnotations[col]); if iAnnotations is not None: lLabel = build_record_label(iAnnotations[col]); node_col = pydot.Node(col, label=lLabel, style="filled", fillcolor=color, fontsize="12.0") graph.add_node(node_col); for col1 in structure[level][col]: lLabel1 = col1 if iAnnotations is not None: lLabel1 = build_record_label(iAnnotations[col1]); color1 = '#%02x%02x%02x' % (255, 255, 128 + int(128 * (1.0 - (level + 2.0) / len(lLevelsReversed)))); node_col1 = pydot.Node(col1, label=lLabel1, style="filled", fillcolor=color1, fontsize="12.0") graph.add_node(node_col1); lEdgeLabel = ""; if iAnnotations is not None: lEdgeLabel = iAnnotations[col + "_" + col1]; lEdge = pydot.Edge(node_col, node_col1, color="red", label=lEdgeLabel, fontsize="12.0") graph.add_edge(lEdge) # print(graph.obj_dict) if(name is not None): graph.write_png(name); else: from IPython.display import Image, display plot1 = Image(graph.create_png()) display(plot1)
Example #12
Source File: render.py From flare-bytecode_graph with Apache License 2.0 | 5 votes |
def dot(self, splines="ortho", show_comments=True, show_hex=False): graph = pydot.Dot(graph_type='digraph', splines=splines, rankdir="TD") graph.set_node_defaults(shape="box", fontname="Courier New", fontsize = "9") blocks = self.get_blocks() edges = self.get_edges(blocks) for start, stop in blocks: lbl = disassemble(self.co, start=start.addr, stop=stop.addr+1, show_labels=False, show_hex=show_hex) if show_comments: comments = self.get_comments(start, stop) for addr, comment, lineno in comments: m = re.search("^[ ]*%d .*$" % addr, lbl, re.MULTILINE) if m is None: continue lbl = lbl[:m.end(0)] + "\n\n# %d " % lineno +\ comment + "\n" + lbl[m.end(0):] # left alignment lbl = lbl.replace("\n", "\\l") lbl += "\\l" tmp = pydot.Node("%08x" % start.addr, label=lbl) graph.add_node(tmp) for edge in edges: tmp = pydot.Edge("%08x" % edge[0].addr, "%08x" % edge[1].addr, color=self.colors[edge[2]]) graph.add_edge(tmp) return graph
Example #13
Source File: trees.py From Projects with MIT License | 5 votes |
def make_graph(graph, root, root_node): for child in root.children: child_node = pydot.Node(get_next_id(), label=child.decision) dot_edge = pydot.Edge(root_node, child_node) graph.add_node(child_node) graph.add_edge(dot_edge) make_graph(graph, child, child_node)
Example #14
Source File: trees.py From Projects with MIT License | 5 votes |
def run_tuple(l,r,u,d): root = Node() make_tree(root, {'L':l, 'R':r, 'U':u, 'D':d}) path_len = sum((l,r,u,d)) paths = filter(lambda x: len(x) == path_len, list_paths(root)) print 'Path Len, Number of paths (%s,%s)' % (path_len, len(paths)) #print '\n'.join([', '.join(x) for x in paths]) #print '' return root, paths
Example #15
Source File: trees.py From Projects with MIT License | 5 votes |
def make_tree(node, state): for d,v in state.iteritems(): if d in transitions[node.decision] and v > 0: child = Node() child.decision = d new_state = state.copy() new_state[d] -= 1 make_tree(child, new_state) node.children.append(child)
Example #16
Source File: dot_parser.py From odoo12-x64 with GNU General Public License v3.0 | 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 #17
Source File: dot_parser.py From odoo13-x64 with GNU General Public License v3.0 | 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 #18
Source File: nx_pydot.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def graphviz_layout(G, prog='neato', root=None): """Create node positions using Pydot and Graphviz. Returns a dictionary of positions keyed by node. Parameters ---------- G : NetworkX Graph The graph for which the layout is computed. prog : string (default: 'neato') The name of the GraphViz program to use for layout. Options depend on GraphViz version but may include: 'dot', 'twopi', 'fdp', 'sfdp', 'circo' root : Node from G or None (default: None) The node of G from which to start some layout algorithms. Returns ------- Dictionary of (x, y) positions keyed by node. Examples -------- >>> G = nx.complete_graph(4) >>> pos = nx.nx_pydot.graphviz_layout(G) >>> pos = nx.nx_pydot.graphviz_layout(G, prog='dot') Notes ----- This is a wrapper for pydot_layout. """ return pydot_layout(G=G, prog=prog, root=root)
Example #19
Source File: Flow.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
def add_edge(self, b1, b2, label="CONT"): """ join two pydot nodes / create nodes edge """ # Edge color based on label text if label=='false': ecolor = "red" elif label=='true': ecolor = 'green' elif label == 'exception': ecolor = 'orange' elif label == 'try': ecolor = 'blue' else: ecolor = 'gray' # node shape based on block type (First or Last instruction) nodes = [None, None] blocks = [b1,b2] for i in range(2): if Block.isTag(blocks[i].instructions[-1], 'isConditional'): ncolor = "cornflowerblue" elif Block.isTag(blocks[i].instructions[0], 'isLabel'): ncolor = "tan" elif Block.isTag(blocks[i].instructions[-1], 'isJump'): ncolor = "darkgreen" elif Block.isTag(blocks[i].instructions[-1],'isCall'): ncolor = "lightyellow4" else: ncolor = "mediumaquamarine" nodes[i] = pydot.Node(b1.label, color=ncolor, style="filled", shape="box", fontname="Courier", fontsize="8") bis="%s\l%s\l" % (blocks[i].label, "\l".join(blocks[i].instructions)) nodes[i].set_name(bis) self.graph.add_node(nodes[i]) ed = pydot.Edge(nodes[0], nodes[1], color=ecolor, label=label, fontname="Courier", fontsize="8", arrowhead="open") self.graph.add_edge(ed)
Example #20
Source File: BST_utils.py From PrincetonAlgorithms with GNU General Public License v2.0 | 5 votes |
def _get_dotnodes(nodes_bst, childnames): """Get a list of pydot Nodes.""" nodes_dot = [] for bstnode in nodes_bst: # Add nodes in the bst nodes_dot.append(pydot.Node(str(bstnode))) # Add null child nodes (e.g., key_right, key_left) for rl in childnames.keys(): if getattr(bstnode, rl) is None: null_child = _get_name_nullchild(bstnode, rl) nodes_dot.append(pydot.Node(null_child, style='invis')) return nodes_dot
Example #21
Source File: model_summaries.py From dnn-quant-ocs with Apache License 2.0 | 5 votes |
def create_pydot_graph(op_nodes, data_nodes, param_nodes, edges, rankdir='TB', styles=None): """Low-level API to create a PyDot graph (dot formatted). """ pydot_graph = pydot.Dot('Net', graph_type='digraph', rankdir=rankdir) op_node_style = {'shape': 'record', 'fillcolor': '#6495ED', 'style': 'rounded, filled'} for op_node in op_nodes: style = op_node_style # Check if we should override the style of this node. if styles is not None and op_node[0] in styles: style = styles[op_node[0]] pydot_graph.add_node(pydot.Node(op_node[0], **style, label="\n".join(op_node))) for data_node in data_nodes: pydot_graph.add_node(pydot.Node(data_node[0], label="\n".join(data_node))) node_style = {'shape': 'oval', 'fillcolor': 'gray', 'style': 'rounded, filled'} if param_nodes is not None: for param_node in param_nodes: pydot_graph.add_node(pydot.Node(param_node[0], **node_style, label="\n".join(param_node))) for edge in edges: pydot_graph.add_edge(pydot.Edge(edge[0], edge[1])) return pydot_graph
Example #22
Source File: nodes.py From transform with Apache License 2.0 | 5 votes |
def validate_value(self, value): assert isinstance(value, pydot.Node)
Example #23
Source File: nodes.py From transform with Apache License 2.0 | 5 votes |
def visit(self, operation_def, input_nodes): num_outputs = operation_def.num_outputs node_name = operation_def.label display_label_rows = ([operation_def.__class__.__name__] + [ _escape('%s: %s' % (field, operation_def.get_field_str(field))) for field in operation_def._fields ]) if operation_def.is_partitionable: display_label_rows.append('partitionable: %s' % True) if num_outputs != 1: ports = '|'.join('<{0}>{0}'.format(idx) for idx in range(num_outputs)) display_label_rows.append('{%s}' % ports) display_label = '{%s}' % '|'.join(display_label_rows) node = pydot.Node(node_name, label=display_label) self._dot_graph.add_node(node) for input_node in input_nodes: self._dot_graph.add_edge(pydot.Edge(input_node, node)) if num_outputs == 1: return (node,) else: return tuple( pydot.Node(obj_dict={'name': '"{}":{}'.format(node_name, idx)}) for idx in range(num_outputs))
Example #24
Source File: dependencies.py From oerplib with GNU Lesser General Public License v3.0 | 5 votes |
def _draw_graph_node(module, tpl): """Generates a Graphviz node named `module`.""" import pydot return pydot.Node(module, margin='0', shape='none', label=tpl)
Example #25
Source File: plot.py From baikal with BSD 3-Clause "New" or "Revised" License | 5 votes |
def dummy_dot_node(name): return pydot.Node( name=quoted(name), shape="rect", color="white", fontcolor="white", fixedsize=True, width=0.0, height=0.0, fontsize=0.0, )
Example #26
Source File: plot.py From baikal with BSD 3-Clause "New" or "Revised" License | 5 votes |
def dot_input_node(name, label): return pydot.Node( name=quoted(name), label=quoted(label), shape="invhouse", color="green" )
Example #27
Source File: model_visualization.py From visual_turing_test-tutorial with MIT License | 5 votes |
def model_picture(model, to_file='local/model.png'): graph = pydot.Dot(graph_type='digraph') if isinstance(model,Sequential): previous_node = None written_nodes = [] n = 1 for node in model.get_config()['layers']: # append number in case layers have same name to differentiate if (node['name'] + str(n)) in written_nodes: n += 1 current_node = pydot.Node(node['name'] + str(n)) written_nodes.append(node['name'] + str(n)) graph.add_node(current_node) if previous_node: graph.add_edge(pydot.Edge(previous_node, current_node)) previous_node = current_node graph.write_png(to_file) elif isinstance(model,Graph): # don't need to append number for names since all nodes labeled for input_node in model.input_config: graph.add_node(pydot.Node(input_node['name'])) # intermediate and output nodes have input defined for layer_config in [model.node_config, model.output_config]: for node in layer_config: graph.add_node(pydot.Node(node['name'])) # possible to have multiple 'inputs' vs 1 'input' if node['inputs']: for e in node['inputs']: graph.add_edge(pydot.Edge(e, node['name'])) else: graph.add_edge(pydot.Edge(node['input'], node['name'])) graph.write_png(to_file)
Example #28
Source File: plot.py From baikal with BSD 3-Clause "New" or "Revised" License | 5 votes |
def dot_node(name, label): return pydot.Node(name=quoted(name), label=quoted(label), shape="rect")
Example #29
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 #30
Source File: XRef.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
def addNodes(str1, str2): global graph node_a = pydot.Node(str1, style="filled", shape="box", color="#cccccc", fontname="Sans", fontsize=8) node_b = pydot.Node(str2, style="filled", shape="box", color="#cccccc", fontname="Sans", fontsize=8) graph.add_node(node_a) graph.add_node(node_b) graph.add_edge(pydot.Edge(node_a, node_b,color="#666666", arrowhead="open", weight=1)) # search for function (mode)references on dir/**/*.smali files