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


Python AGraph.add_node方法代码示例

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


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

示例1: get_graphviz

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
    def get_graphviz(self, triple_args_function=None,
                     ignore_properties=VIS_IGNORE_PROPERTIES):
        """
        Create a pygraphviz graph from the tree
        """
        def _id(node):
            return node.uri.split("/")[-1]
        g = AGraph(directed=True)
        triples = list(self.get_triples())
        nodeset = set(chain.from_iterable((t.subject, t.object)
                                          for t in triples))
        for n in nodeset:
            label = "%s: %s" % (n.id, n.word)
            for k, v in n.__dict__.iteritems():
                if k not in ignore_properties:
                    label += "\\n%s: %s" % (k, v)
            g.add_node(_id(n), label=label)

        # create edges
        for triple in triples:
            kargs = (triple_args_function(triple)
                     if triple_args_function else {})
            if 'label' not in kargs:
                kargs['label'] = triple.predicate
            g.add_edge(_id(triple.subject), _id(triple.object), **kargs)
        # some theme options
        g.graph_attr["rankdir"] = "BT"
        g.node_attr["shape"] = "rect"
        g.edge_attr["edgesize"] = 10
        g.node_attr["fontsize"] = 10
        g.edge_attr["fontsize"] = 10

        return g
开发者ID:anonymous-1,项目名称:syntaxrules,代码行数:35,代码来源:syntaxtree.py

示例2: render

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
    def render(self, filename):
        g = AGraph(strict=False, directed=True)

        # create nodes
        for frame_id, node in self.callers.items():
            label = "{ %s }" % node
            g.add_node(frame_id, shape='Mrecord', label=label,
                       fontsize=13, labelfontsize=13)

        # create edges
        for frame_id, node in self.callers.items():
            child_nodes = []
            for child_id in node.child_methods:
                child_nodes.append(child_id)
                g.add_edge(frame_id, child_id)

            # order edges l to r
            if len(child_nodes) > 1:
                sg = g.add_subgraph(child_nodes, rank='same')
                sg.graph_attr['rank'] = 'same'
                prev_node = None
                for child_node in child_nodes:
                    if prev_node:
                        sg.add_edge(prev_node, child_node, color="#ffffff")
                    prev_node = child_node

        g.layout()
        g.draw(path=filename, prog='dot')

        print("callviz: rendered to %s" % filename)
        self.clear()
开发者ID:xapiton,项目名称:rcviz,代码行数:33,代码来源:rcviz.py

示例3: path_graph

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
def path_graph(nodes):
    graph = AGraph(directed=True)

    for node in nodes:
        graph.add_node(node, shape='rectangle')

    graph.add_path(nodes)
    return graph
开发者ID:lorenanicole,项目名称:pytenn2016,代码行数:10,代码来源:diagrams.py

示例4: draw_workflow

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
def draw_workflow(filename, workflow):
    dot = AGraph(directed=True, strict=False)  # (comment="Computing scheme")
    for i, n in workflow.nodes.items():
        dot.add_node(i, label="{0} \n {1}".format(n.foo.__name__, _format_arg_list(n.bound_args.args, None)))

    for i in workflow.links:
        for j in workflow.links[i]:
            dot.add_edge(i, j[0], j[1].name)  # , headlabel=j[1].name, labeldistance=1.8)
    dot.layout(prog="dot")

    dot.draw(filename)
开发者ID:NLeSC,项目名称:noodles,代码行数:13,代码来源:draw_workflow.py

示例5: _render

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
	def _render(self, costs=False, word_probs=False, highlight_best=False):	
		from pygraphviz import AGraph
                graph = AGraph(directed=True)
                for node_id, node_label in self.nodes.iteritems():
                        attributes = self._node_attr(node_id, costs=costs, word_probs=word_probs)
			graph.add_node(node_id, **attributes)
                for (parent_node_id, child_node_id) in self.edges:
                        graph.add_edge(parent_node_id, child_node_id)
		self.graph = graph
		if highlight_best:
			self._highlight_best()
开发者ID:andre-martins,项目名称:nematus,代码行数:13,代码来源:hypgraph.py

示例6: render_local

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
 def render_local(self, filename):
     """Renders the OBST image locally using pygraphviz."""
     # Get the graph information
     node_list, edge_list = self.__generate_image()
     # Generate the graph
     from pygraphviz import AGraph
     G=AGraph(strict=True,directed=True)    # Create a graph
     for node in node_list:
         G.add_node(node)
     for edge in edge_list:
         G.add_edge(edge[0], edge[1])        
     G.layout('dot')                         # Set hierarchical layout
     G.draw(filename)                        # Save the image.
开发者ID:aladagemre,项目名称:misc,代码行数:15,代码来源:optimalbst.py

示例7: as_graph

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
 def as_graph(self, to=None):
     from pygraphviz import AGraph
     g = AGraph(directed=True)
     
     for a in self.activities.values():
         g.add_node(a.title, label=a.title)
         
     for t in self.transitions.values():
         g.add_edge(t.input.title, t.output.title, label=t.name)
     
     if to:
         g.write(to)
     else:
         return str(g)
开发者ID:AMHZR,项目名称:goflow,代码行数:16,代码来源:process_builder.py

示例8: to_dot

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
 def to_dot(self, filename, edges):
     from pygraphviz import AGraph
     dot = AGraph(directed=True)
     for n in edges.keys():
         dot.add_node(str(n))
         if lib.qcgc_arena_get_blocktype(ffi.cast("cell_t *", n)) not in [
                 lib.BLOCK_BLACK, lib.BLOCK_WHITE]:
             node = dot.get_node(str(n))
             node.attr['color'] = 'red'
     for n in edges.keys():
         if edges[n] is not None:
             dot.add_edge(str(n), str(edges[n]))
     dot.layout(prog='dot')
     dot.draw(filename)
开发者ID:ntruessel,项目名称:qcgc,代码行数:16,代码来源:test_stressing.py

示例9: render_image

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
	def render_image(self, filename):
		"""Renders the graph image locally using pygraphviz."""
		
		# Create a graph
		G=AGraph(directed=False) 
		# Add nodes
		for node in self.nodes:
			G.add_node(node)
		# Add edges
		for edge in self.edges:
			G.add_edge(edge[0], edge[1], color='blue')
		# Give layout and draw.
		G.layout('circo')
		G.draw(filename) # Save the image.
		
		# Display the output image.
		os.system("gwenview %s&" % filename)
开发者ID:aladagemre,项目名称:misc,代码行数:19,代码来源:independent_set.py

示例10: cm_json_to_graph

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
def cm_json_to_graph(im_json):
    """Return pygraphviz Agraph from Kappy's contact map JSON.

    Parameters
    ----------
    im_json : dict
        A JSON dict which contains a contact map generated by Kappy.

    Returns
    -------
    graph : pygraphviz.Agraph
        A graph representing the contact map.
    """
    cmap_data = im_json['contact map']['map']

    # Initialize the graph
    graph = AGraph()

    # In this loop we add sites as nodes and clusters around sites to the
    # graph. We also collect edges to be added between sites later.
    edges = []
    for node_idx, node in enumerate(cmap_data):
        sites_in_node = []
        for site_idx, site in enumerate(node['node_sites']):
            # We map the unique ID of the site to its name
            site_key = (node_idx, site_idx)
            sites_in_node.append(site_key)
            graph.add_node(site_key, label=site['site_name'], style='filled',
                           shape='ellipse')
            # Each port link is an edge from the current site to the
            # specified site
            if not site['site_type'] or not site['site_type'][0] == 'port':
                continue
            for port_link in site['site_type'][1]['port_links']:
                edge = (site_key, tuple(port_link))
                edges.append(edge)
        graph.add_subgraph(sites_in_node,
                           name='cluster_%s' % node['node_type'],
                           label=node['node_type'])

    # Finally we add the edges between the sites
    for source, target in edges:
        graph.add_edge(source, target)

    return graph
开发者ID:johnbachman,项目名称:indra,代码行数:47,代码来源:kappa_util.py

示例11: get_dot

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
    def get_dot(self, labeller=None):
        self.labeller = labeller

        a_graph = AGraph(directed=True)
        nx_graph = self.graph.nx_graph

        # TODO: Add some default stuff?
        # a_graph.graph_attr.update(N.graph.get('graph',{}))
        # a_graph.node_attr.update(N.graph.get('node',{}))
        # a_graph.edge_attr.update(N.graph.get('edge',{}))

        structural_nodes = []
        output_nodes = []
        input_nodes = []
        # First, add nodes
        for node in nx_graph.nodes():
            name, attrs = self.get_node_attributes(node)
            if self.graph.is_input(node):
                input_nodes.append(name)
            elif self.graph.is_structural(node):
                structural_nodes.append(name)
            elif self.graph.is_output(node):
                output_nodes.append(name)

            # Keep a reference to the original node
            a_graph.add_node(name, **attrs)

        # We need to add subgraphs to cluster stuff on rank
        sub = a_graph.add_subgraph(input_nodes, name='input')
        sub.graph_attr['rank'] = 'source'
        sub = a_graph.add_subgraph(structural_nodes, name='structural')
        sub.graph_attr['rank'] = 'same'
        sub = a_graph.add_subgraph(output_nodes, name='output')
        sub.graph_attr['rank'] = 'sink'

        # Now add edges
        for u, v, edgedata in nx_graph.edges_iter(data=True):
            attrs = {}
            a_graph.add_edge(self.graph.node_to_name(u),
                             self.graph.node_to_name(v),
                             **attrs)

        return a_graph
开发者ID:brettc,项目名称:bricolage,代码行数:45,代码来源:dot_layout.py

示例12: render_image

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
def render_image(node_list, edge_list):
        # Generate the graph
        from pygraphviz import AGraph
        G=AGraph(strict=False,directed=True)    # Create a graph
        for node in node_list:
            G.add_node(node)
        for edge in edge_list:
            G.add_edge(edge[0], edge[1])
        G.layout('dot')                         # Set hierarchical layout

        filename = str(time())
        postfix = 0
        while exists(filename+str(postfix)+".png"):
            postfix+=1
        filename += str(postfix) + ".png"
        G.draw(filename)                        # Save the image.

        with open(filename, "rb") as handle:
         return xmlrpclib.Binary(handle.read())
开发者ID:aladagemre,项目名称:misc,代码行数:21,代码来源:rpcserver.py

示例13: write_graph

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
def write_graph(probs, path):
    graph = AGraph(directed=True)
    next_label = 0
    labels = {}
    for from_state, to_states in probs.iteritems():
        if from_state not in labels:
            labels[from_state] = next_label
            next_label += 1
        for to_state in to_states:
            if to_state not in labels:
                labels[to_state] = next_label
                next_label += 1
    for label in xrange(next_label):
        graph.add_node(label, fillcolor="blue", label="", style="filled")
    for from_state, to_states in probs.iteritems():
        for to_state, prob in to_states.iteritems():
            graph.add_edge(labels[from_state], labels[to_state], label="%.2g" % prob)
    # prog: neato (default), dot, twopi, circo, fdp or nop.
    graph.layout()
    graph.draw(path)
开发者ID:Man-UP,项目名称:monkey-drummer,代码行数:22,代码来源:graph.py

示例14: get_graphviz

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
 def get_graphviz(self, triple_hook=graphviz_triple_hook,
                  node_hook=graphviz_node_hook,
                  theme_options=VIS_THEME_OPTIONS, **hook_options):
     """
     Create a pygraphviz graph from the tree
     @param triple_hook: a function that returns an attribute dict (or None)
                         given a triple and the kargs
     @param node_hook: a function that returns a label given a node
                        and the kargs
     @param theme_options: a dict-of-dicts containing global
                           graph/node/edge attributes
     @param hook_options: additional arguments to pass to the hook functions
     """
     def _id(node):
         return node.uri.split("/")[-1]
     g = AGraph(directed=True, strict=False)
     triples = list(self.get_triples())
     # create nodes
     nodeset = set(chain.from_iterable((t.subject, t.object)
                                       for t in triples))
     for n in sorted(nodeset, key=lambda n:n.id):
         g.add_node(_id(n), **node_hook(n, **hook_options))
     connected = set()
     # create edges
     for triple in sorted(triples, key=lambda t:t.predicate):
         kargs = triple_hook(triple, **hook_options)
         if kargs:
             if kargs.get('reverse'):
                 g.add_edge(_id(triple.object), _id(triple.subject), **kargs)
             else:
                 g.add_edge(_id(triple.subject), _id(triple.object), **kargs)
             connected |= {_id(triple.subject), _id(triple.object)}
     connected = chain.from_iterable(g.edges())
     for isolate in set(g.nodes()) - set(connected):
         g.remove_node(isolate)
     # some theme options
     for obj, attrs in theme_options.iteritems():
         for k, v in attrs.iteritems():
             getattr(g, "%s_attr" % obj)[k] = v
     return g
开发者ID:vanatteveldt,项目名称:syntaxrules,代码行数:42,代码来源:syntaxtree.py

示例15: _drawmap

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import add_node [as 别名]
def _drawmap(fs, rulename=None):
    """Draw a map of the firewalls and their connections based on their interfaces.
    If nulename is specified, draw also the sources and dests for a that rule.  #TODO: implement this
    """
    A = AGraph()
    A.graph_attr['bgcolor'] = 'transparent'
#    A.graph_attr['size'] = '8,5'
    # Draw hosts
    for h in fs.hosts:
        A.add_node(h.hostname)
        if h.network_fw in (1, True, '1'): # network firewall
            f = Node(A, h.hostname)
            f.attr['color']  = 'red'

    # Draw nets
    for net in fs.networks:
        A.add_node(net.name)
        poly = Node(A, net.name)
        poly.attr['shape'] = 'polygon'
        poly.attr['sides'] = '8'

    # Connect hosts to nets
    for host in fs.hosts:
        on_Internet = True
        for net in fs.networks:
            if host in net:
                on_Internet = False
                A.add_edge(host.hostname, net.name)
                e = Edge(A, host.hostname, net.name)
                e.attr['label'] = host.iface
                e.attr['fontsize'] = '6'
        # If a host is not in any configured net, it's on the Internet
        if on_Internet:
            A.add_edge(host.hostname, 'Internet')
            e = Edge(A, host.hostname, 'Internet')
            e.attr['label'] = host.iface
            e.attr['fontsize'] = '6'

    A.layout(prog='circo')
    return A
开发者ID:Mika64,项目名称:firelet,代码行数:42,代码来源:flmap.py


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