当前位置: 首页>>代码示例>>Python>>正文


Python pydot.Dot方法代码示例

本文整理汇总了Python中pydot.Dot方法的典型用法代码示例。如果您正苦于以下问题:Python pydot.Dot方法的具体用法?Python pydot.Dot怎么用?Python pydot.Dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydot的用法示例。


在下文中一共展示了pydot.Dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
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)) 
开发者ID:amimo,项目名称:dcc,代码行数:23,代码来源:graph.py

示例2: parse_dot_data

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def parse_dot_data(s):
    """Parse DOT description in (unicode) string `s`.

    @return: Graphs that result from parsing.
    @rtype: `list` of `pydot.Dot`
    """
    global top_graphs
    top_graphs = list()
    try:
        graphparser = graph_definition()
        graphparser.parseWithTabs()
        tokens = graphparser.parseString(s)
        return list(tokens)
    except ParseException as err:
        print(
            err.line +
            " "*(err.column-1) + "^" +
            err)
        return None 
开发者ID:pydot,项目名称:pydot,代码行数:21,代码来源:dot_parser.py

示例3: plot_hierarchy

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
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') 
开发者ID:cvjena,项目名称:semantic-embeddings,代码行数:22,代码来源:plot_hierarchy.py

示例4: _check_pydot

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def _check_pydot():
    """Raise errors if `pydot` or GraphViz unavailable."""
    if pydot is None:
        raise ImportError(
            'Failed to import `pydot`. '
            'Please install `pydot`. '
            'For example with `pip install pydot`.')
    try:
        # Attempt to create an image of a blank graph
        # to check the pydot/graphviz installation.
        pydot.Dot.create(pydot.Dot())
    except OSError:
        raise OSError(
            '`pydot` failed to call GraphViz.'
            'Please install GraphViz (https://www.graphviz.org/) '
            'and ensure that its executables are in the $PATH.') 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,代码来源:vis_utils.py

示例5: draw

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def draw(self, name, dname, draw_branches=True):
        from pydot import Dot, Edge
        g = Dot()
        g.set_node_defaults(color='lightgray', style='filled', shape='box',
                            fontname='Courier', fontsize='10')
        for node in sorted(self.nodes, key=lambda x: x.num):
            if draw_branches and node.type.is_cond:
                g.add_edge(Edge(str(node), str(node.true), color='green'))
                g.add_edge(Edge(str(node), str(node.false), color='red'))
            else:
                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)) 
开发者ID:DroidTest,项目名称:TimeMachine,代码行数:19,代码来源:graph.py

示例6: save

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def save(self, cf, filename, format='dot'):
        """Save basic block graph into a file.
        """
        try:
            dot_graph = Dot(**self.graph_format)

            # add nodes
            nodes = {}
            for cfg_addr in cf._graph.node.keys():
                nodes[cfg_addr] = self._create_node(cfg_addr, cf)

                dot_graph.add_node(nodes[cfg_addr])

            # add edges
            for cfg_src_addr in cf._graph.node.keys():
                for cfg_dst_addr in cf._edges.get(cfg_src_addr, []):
                    edge = self._create_edge(nodes, cfg_src_addr, cfg_dst_addr)

                    dot_graph.add_edge(edge)

            dot_graph.write("{}.{}".format(filename, format), format=format)
        except Exception:
            logger.error("Failed to save call graph: %s (%s)", filename, format, exc_info=True) 
开发者ID:programa-stic,项目名称:barf-project,代码行数:25,代码来源:callgraph.py

示例7: write

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def write(self, *args, **kwargs):
        """Write the resulting graph in a file.
        It is just a wrapper around the :func:`pydot.Dot.write` method
        (see the `pydot <http://code.google.com/p/pydot/>`_ documentation for
        details).  Below a common way to use it::

            >>> graph = oerp.inspect.relations(['res.partner'])
            >>> graph.write('relations_res_partner.png', format='png')

        About supported formats, consult the
        `Graphviz documentation <http://www.graphviz.org/doc/info/output.html>`_.
        """
        output = self.make_dot()
        return output.write(*args, **kwargs)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: 
开发者ID:osiell,项目名称:oerplib,代码行数:18,代码来源:relations.py

示例8: write

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def write(self, *args, **kwargs):
        """Write the resulting graph in a file.
        It is just a wrapper around the :func:`pydot.Dot.write` method
        (see the `pydot <http://code.google.com/p/pydot/>`_ documentation for
        details).  Below a common way to use it::

            >>> graph = oerp.inspect.dependencies(['base'], ['res.partner'])
            >>> graph.write('dependencies_res_partner.png', format='png')
        
        About supported formats, consult the
        `Graphviz documentation <http://www.graphviz.org/doc/info/output.html>`_.
        """
        output = self.make_dot()
        return output.write(*args, **kwargs)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: 
开发者ID:osiell,项目名称:oerplib,代码行数:18,代码来源:dependencies.py

示例9: draw

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def draw(self, name, dname, draw_branches=True):
        from pydot import Dot, Edge
        g = Dot()
        g.set_node_defaults(color='lightgray',
                            style='filled',
                            shape='box',
                            fontname='Courier',
                            fontsize='10')
        for node in sorted(self.nodes, key=lambda x: x.num):
            if draw_branches and node.type.is_cond:
                g.add_edge(Edge(str(node), str(node.true), color='green'))
                g.add_edge(Edge(str(node), str(node.false), color='red'))
            else:
                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)) 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:24,代码来源:graph.py

示例10: draw

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def draw(self, name, dname, draw_branches=True):
        import pydot
        g = pydot.Dot()
        g.set_node_defaults(**{'color': 'lightgray', 'style': 'filled',
                    'shape': 'box', 'fontname': 'Courier', 'fontsize': '10'})
        for node in sorted(self.nodes, key=lambda x: x.num):
            if draw_branches and node.is_cond():
                edge_true = pydot.Edge(str(node), str(node.true))
                edge_false = pydot.Edge(str(node), str(node.false))
                edge_true.set_color('green')
                edge_false.set_color('red')
                g.add_edge(edge_true)
                g.add_edge(edge_false)
            else:
                succs = self.sucs(node)
                for suc in succs:
                    edge = pydot.Edge(str(node), str(suc))
                    edge.set_color('blue')
                    g.add_edge(edge)
        g.write_png('%s/%s.png' % (dname, name)) 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:22,代码来源:graph.py

示例11: wr_png

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
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)) 
开发者ID:dvklopfenstein,项目名称:PrincetonAlgorithms,代码行数:19,代码来源:Digraph.py

示例12: wr_png

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
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)) 
开发者ID:dvklopfenstein,项目名称:PrincetonAlgorithms,代码行数:20,代码来源:BaseComp.py

示例13: wr_png_array

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
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)) 
开发者ID:dvklopfenstein,项目名称:PrincetonAlgorithms,代码行数:27,代码来源:binary_heaps.py

示例14: wr_png

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
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)) 
开发者ID:dvklopfenstein,项目名称:PrincetonAlgorithms,代码行数:19,代码来源:Graph.py

示例15: wr_png

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Dot [as 别名]
def wr_png(fout_png, nodes_bst, childnames, log):
    """Save tree figure to png file."""
    # 1. create/initialize graph
    g = pydot.Dot(graph_type='digraph') # directed graph
    # 2. create pydot Nodes
    nodes_dot = _get_dotnodes(nodes_bst, childnames)
    # 3. add nodes to graph
    for dotnode in nodes_dot:
        g.add_node(dotnode)
    # 4. add edges between nodes to graph
    edges_dot = _get_dotedges(nodes_bst, childnames)
    for dotedge in edges_dot:
        g.add_edge(dotedge)
    # 5. write graph to png file
    g.write_png(fout_png)
    log.write("  wrote: {}\n".format(fout_png)) 
开发者ID:dvklopfenstein,项目名称:PrincetonAlgorithms,代码行数:18,代码来源:BST_utils.py


注:本文中的pydot.Dot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。