How to use the pydot.Dot function in pydot

To help you get started, we’ve selected a few pydot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dvklopfenstein / PrincetonAlgorithms / py / AlgsSedgewickWayne / testcode / binary_heaps.py View on Github external
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)
github pymc-devs / pymc3 / PyMC2 / Model.py View on Github external
'fig', 'svg', 'svgz', 'dia', 'dot', 'canon', 'plain', 'plain-ext', 'xdot'

        format='raw' outputs a GraphViz dot file.

        Returns the pydot 'dot' object for further user manipulation.
        """

        if not self._prepared:
            self._prepare()

        if self.__name__ == None:
            self.__name__ = model

        import pydot

        self.dot_object = pydot.Dot()

        pydot_nodes = {}
        pydot_subgraphs = {}

        # Create the pydot nodes from pymc objects
        for datum in self.data:
            pydot_nodes[datum] = pydot.Node(name=datum.__name__,shape='box')
            self.dot_object.add_node(pydot_nodes[datum])

        for parameter in self.parameters:
            pydot_nodes[parameter] = pydot.Node(name=parameter.__name__)
            self.dot_object.add_node(pydot_nodes[parameter])

        for node in self.nodes:
            pydot_nodes[node] = pydot.Node(name=node.__name__,shape='invtriangle')
            self.dot_object.add_node(pydot_nodes[node])
github microsoft / tensorwatch / tensorwatch / model_graph / hiddenlayer / pytorch_draw_model.py View on Github external
def create_pydot_graph(op_nodes_desc, 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_desc:
        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[1:])))

    node_style = {'shape': 'oval',
github onnx / onnx / onnx / tools / net_drawer.py View on Github external
def GetPydotGraph(
    graph,  # type: GraphProto
    name=None,  # type: Optional[Text]
    rankdir='LR',  # type: Text
    node_producer=None,  # type: Optional[_NodeProducer]
    embed_docstring=False,  # type: bool
):  # type: (...) -> pydot.Dot
    if node_producer is None:
        node_producer = GetOpNodeProducer(embed_docstring=embed_docstring, **OP_STYLE)
    pydot_graph = pydot.Dot(name, rankdir=rankdir)
    pydot_nodes = {}  # type: Dict[Text, pydot.Node]
    pydot_node_counts = defaultdict(int)  # type: Dict[Text, int]
    for op_id, op in enumerate(graph.node):
        op_node = node_producer(op, op_id)
        pydot_graph.add_node(op_node)
        for input_name in op.input:
            if input_name not in pydot_nodes:
                input_node = pydot.Node(
                    _escape_label(
                        input_name + str(pydot_node_counts[input_name])),
                    label=_escape_label(input_name),
                    **BLOB_STYLE
                )
                pydot_nodes[input_name] = input_node
            else:
                input_node = pydot_nodes[input_name]
github santoshphilip / eppy / diagrams / s_airloop2.py View on Github external
def makediagram(edges):
    """make the diagram with the edges"""
    graph = pydot.Dot(graph_type='digraph')
    nodes = edges2nodes(edges)
    epnodes = [(node, 
        makeanode(node[0])) for node in nodes if nodetype(node)=="epnode"]
    endnodes = [(node, 
        makeendnode(node[0])) for node in nodes if nodetype(node)=="EndNode"]
    epbr = [(node, makeabranch(node)) for node in nodes if not istuple(node)]
    nodedict = dict(epnodes + epbr + endnodes)
    for value in nodedict.values():
        graph.add_node(value)
    for e1, e2 in edges:
        graph.add_edge(pydot.Edge(nodedict[e1], nodedict[e2]))
    return graph
github softdevteam / eco / lib / eco / viewer.py View on Github external
def create_pydot_graph(self, graph):
        pydotgraph = pydot.Dot(graph_type='digraph')

        i = 0
        for stateset in graph.state_sets:
            stateset_info = []
            for state in stateset.elements:
                stateset_info.append(str(state) + "{" + str(stateset.lookaheads[state]) + "}")
            dotnode = pydot.Node(i, shape='rect', label="%s\n%s" % (i, "\n".join(stateset_info)))
            pydotgraph.add_node(dotnode)
            i += 1

        for key in list(graph.edges.keys()):
            start = key[0]
            end = graph.edges[key]
            pydotgraph.add_edge(pydot.Edge(pydot.Node(start), pydot.Node(end), label=key[1].name))

        pydotgraph.write_png(tempdir + 'graphtemp.png')
github lzuwei / ip-avsr / utils / draw_net.py View on Github external
"""
    Creates a PyDot graph of the network defined by the given layers.
    :parameters:
        - layers : list
            List of the layers, as obtained from lasange.layers.get_all_layers
        - output_shape: (default `True`)
            If `True`, the output shape of each layer will be displayed.
        - verbose: (default `False`)
            If `True`, layer attributes like filter shape, stride, etc.
            will be displayed.
        - verbose:
    :returns:
        - pydot_graph : PyDot object containing the graph

    """
    pydot_graph = pydot.Dot('Network', graph_type='digraph')
    pydot_nodes = {}
    pydot_edges = []
    for i, layer in enumerate(layers):
        layer_type = '{0}: {1}'.format(layer.__class__.__name__, layer.name)
        key = repr(layer)
        label = layer_type
        color = get_hex_color(layer_type)
        if verbose:
            for attr in ['num_filters', 'num_units', 'ds',
                         'filter_shape', 'stride', 'strides', 'p']:
                if hasattr(layer, attr):
                    label += '\n' + \
                        '{0}: {1}'.format(attr, getattr(layer, attr))
            if hasattr(layer, 'nonlinearity'):
                try:
                    nonlinearity = layer.nonlinearity.__name__
github santoshphilip / eppy / p3 / eppy / ex_loopdiagram.py View on Github external
def makediagram(edges):
    """make the diagram with the edges"""
    graph = pydot.Dot(graph_type='digraph')
    nodes = edges2nodes(edges)
    epnodes = [(node, 
        makeanode(node[0])) for node in nodes if nodetype(node)=="epnode"]
    endnodes = [(node, 
        makeendnode(node[0])) for node in nodes if nodetype(node)=="EndNode"]
    epbr = [(node, makeabranch(node)) for node in nodes if not istuple(node)]
    nodedict = dict(epnodes + epbr + endnodes)
    for value in list(nodedict.values()):
        graph.add_node(value)
    for e1, e2 in edges:
        graph.add_edge(pydot.Edge(nodedict[e1], nodedict[e2]))
    return graph
github santoshphilip / eppy / eppy / airloop / s_airloop3.py View on Github external
def makediagram(edges):
    """make the diagram with the edges"""
    graph = pydot.Dot(graph_type='digraph')
    nodes = edges2nodes(edges)
    epnodes = [(node, 
        makeanode(node[0])) for node in nodes if nodetype(node)=="epnode"]
    endnodes = [(node, 
        makeendnode(node[0])) for node in nodes if nodetype(node)=="EndNode"]
    epbr = [(node, makeabranch(node)) for node in nodes if not istuple(node)]
    nodedict = dict(epnodes + epbr + endnodes)
    for value in nodedict.values():
        graph.add_node(value)
    for e1, e2 in edges:
        graph.add_edge(pydot.Edge(nodedict[e1], nodedict[e2]))
    return graph
github casadi / casadi / swig / python / tools / graph / graph.py View on Github external
SX.__hash__ = getHashSX

    # Get the dependencies and inverse dependencies in a dict
    dep, invdep = dependencyGraph(s,{},{})

    allnodes = set(dep.keys()).union(set(invdep.keys()))

    #print "a", set(dep.keys()), [i.__hash__() for i in dep.keys()]
    #print "b", set(invdep.keys()), [i.__hash__() for i in invdep.keys()]
    #print "allnodes", allnodes, [i.__hash__() for i in allnodes]

    #return None

    artists = {}

    graph = pydot.Dot('G', graph_type='digraph',rankdir=direction)

    for node in allnodes:
      artists[node] = createArtist(node,dep=dep,invdep=invdep,graph=graph,artists=artists,**kwargs)

    for artist in artists.values():
      if artist is None: continue
      artist.draw()

    open('source.dot','w').write(graph.to_string())
  finally:
    SX.__hash__ = SX__hash__backup
  return graph