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


Python pydot.Node方法代码示例

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


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

示例1: draw

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [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: plot_hierarchy

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [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

示例3: _create_node

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

示例4: wr_png

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [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

示例5: wr_png

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [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

示例6: wr_png_array

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [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

示例7: wr_png

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [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

示例8: get_network

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

示例9: render_node_graphviz

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

示例10: model_picture

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [as 别名]
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) 
开发者ID:mateuszmalinowski,项目名称:visual_turing_test-tutorial,代码行数:38,代码来源:model_visualization.py

示例11: createModelGraph

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [as 别名]
def createModelGraph(world, filename="modelgraph"):
    '''
    This method creates a graph of the models used by the agents
    '''
    modelgraph = pydot.Dot('Model graph', graph_type='digraph') 
    for agent in world.agents.values():
        for my_model in list(agent.models.keys()):
            name = agent.name + ' ' + str(my_model)
            node_src = pydot.Node(name)
            if node_src.get_name() not in modelgraph.obj_dict['nodes'].keys():
                modelgraph.add_node(node_src)
            if world.agents[agent.name].models[my_model].has_key('beliefs'):
                beliefs = world.agents[agent.name].models[my_model]['beliefs']
                if beliefs != True:
                    for belief,pct in beliefs.items():
                        split = belief.replace('\t','\n').split('\n')
                        for line in split:
                            if '_model' in line:
                                modeled_agent_name = line.split("'")[0]
                                model_num = int(float(line.split(')')[-1].strip().split(': ')[1]))
                                model_key = world.agents[modeled_agent_name].index2model(model_num)
                                name = modeled_agent_name + ' ' + model_key
                                node_dst = pydot.Node(name)
                                if node_dst.get_name() not in modelgraph.obj_dict['nodes'].keys():
                                    modelgraph.add_node(node_dst)
                                if not modelgraph.get_edge(node_src.get_name(), node_dst.get_name()):
                                    edge = pydot.Edge(node_src, node_dst, label=str(pct))
                                    modelgraph.add_edge(edge)
                                else:
                                    old_edge = modelgraph.get_edge(node_src.get_name(), node_dst.get_name())[0]
                                    old_pct = old_edge.get_attributes()['label']
                                    modelgraph.del_edge(node_src, node_dst)
                                    edge = pydot.Edge(node_src, node_dst, label=str(float(old_pct)+pct))
                                    modelgraph.add_edge(edge)

    modelgraph.write_png(filename+'.png') 
开发者ID:pynadath,项目名称:psychsim,代码行数:38,代码来源:graph.py

示例12: push_node_stmt

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

示例13: test_add_style

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [as 别名]
def test_add_style(self):

        g = pydot.Dot(graph_name='Test', graph_type='graph')

        node = pydot.Node('mynode')
        node.add_style('abc')
        self.assertEqual( node.get_style(), 'abc' )
        node.add_style('def')
        self.assertEqual( node.get_style(), 'abc,def' )
        node.add_style('ghi')
        self.assertEqual( node.get_style(), 'abc,def,ghi' ) 
开发者ID:pydot,项目名称:pydot,代码行数:13,代码来源:pydot_unittest.py

示例14: test_create_simple_graph_with_node

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [as 别名]
def test_create_simple_graph_with_node(self):

        g = pydot.Dot()
        g.set_type('digraph')
        node = pydot.Node('legend')
        node.set("shape", 'box')
        g.add_node(node)
        node.set('label', 'mine')
        s = g.to_string()
        expected = 'digraph G {\nlegend [label=mine, shape=box];\n}\n'
        assert s == expected 
开发者ID:pydot,项目名称:pydot,代码行数:13,代码来源:pydot_unittest.py

示例15: test_graph_pickling

# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import Node [as 别名]
def test_graph_pickling(self):


        g = pydot.Graph()
        s = pydot.Subgraph("foo")
        g.add_subgraph(s)
        g.add_edge( pydot.Edge('A','B') )
        g.add_edge( pydot.Edge('A','C') )
        g.add_edge( pydot.Edge( ('D','E') ) )
        g.add_node( pydot.Node( 'node!' ) )
        pickle.dumps(g) 
开发者ID:pydot,项目名称:pydot,代码行数:13,代码来源:pydot_unittest.py


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