• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pygraphviz.AGraph类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: run_graph

 def run_graph(dot):
     """ Runs graphviz to see if the syntax is good. """
     graph = AGraph()
     graph = graph.from_string(dot)
     extension = 'png'
     graph.draw(path='output.png', prog='dot', format=extension)
     sys.exit(0)
开发者ID:aaron0browne,项目名称:eralchemy,代码行数:7,代码来源:test_intermediary_to_dot.py


示例2: build_graph

def build_graph(ts):
    g = AGraph(directed=True)
    g.add_edges_from(ts.ts.todok().keys())
    g.graph_attr['overlap'] = 'scalexy'
    for n, s in zip(g.nodes(), ts._pwa.states):
        n.attr['label'] = s
    return g
开发者ID:fran-penedo,项目名称:param-synth-web,代码行数:7,代码来源:graph.py


示例3: get_graphviz

    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,代码行数:33,代码来源:syntaxtree.py


示例4: graphviz_to_firebase

def graphviz_to_firebase(dirname,filename):
    """
    since several chars must be escaped from firebase keys,
    (see #http://stackoverflow.com/questions/19132867/adding-firebase-data-dots-and-forward-slashes
    we can't directly use them as keys so:
    - we use integer i as key,
    - "nodes" dict maps node name to i to preserve edges coherency
    - node name is kept as default node label
    """
    f=os.path.join(dirname, filename)
    graph=filename.split('.')[0]
    print('processing %s'%f),
    agraph=AGraph(f)
    nodes={}
    for i,node in enumerate(agraph.iternodes()):
        nodes[node]=i
        attrs={}
        attrs.update(agraph.node_attr)
        attrs['label']=node #default label is node id
        attrs.update(node.attr)
        key='%s/node/%d'%(graph,i)
        ref.patch(key,attrs)
        print('.'),
    for i,edge in enumerate(agraph.iteredges()):
        attrs={}
        attrs.update(agraph.edge_attr)
        attrs.update(edge.attr)
        attrs['source']=nodes[edge[0]]
        attrs['target']=nodes[edge[1]]
        #edges are added as attributes of their destination node
        key='%s/edge/%d'%(graph,i)
        ref.patch(key,attrs)
        print('-'),
    logging.info('ok')
开发者ID:goulu,项目名称:firegraph,代码行数:34,代码来源:graphviz2firegraph.py


示例5: render

    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,代码行数:31,代码来源:rcviz.py


示例6: draw

 def draw(self):
     tree = self.to_tree()
     A = AGraph(tree)
     if not self.filename:
         self.filename = input('Please input a filename:')
     A.draw('temp/{}.jpg'.format(self.filename),
            format='jpg', prog='fdp')
开发者ID:ccdd9451,项目名称:GS-Parser,代码行数:7,代码来源:s_browser.py


示例7: path_graph

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,代码行数:8,代码来源:diagrams.py


示例8: processLines

    def processLines(self):
        if len(self.lines) == 0:
            return
        
        self.identifier = self.lines[0][2:]

        s = '\n'.join(self.lines)
        A = AGraph()
        G = A.from_string(s)
        self.processGraph(G)
开发者ID:a0x77n,项目名称:joern-tools,代码行数:10,代码来源:GraphvizTool.py


示例9: dot_to_graph

def dot_to_graph(dot, output_path):
    """
    Render by calling graphviz the figure on the output path.
    :param dot: str with the
    :param output_path:
    :return:
    """
    from pygraphviz import AGraph
    graph = AGraph().from_string(dot)
    graph.draw(path=output_path, prog='dot')
开发者ID:ColinHuang,项目名称:draw-compose,代码行数:10,代码来源:draw_compose.py


示例10: _render

	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,代码行数:11,代码来源:hypgraph.py


示例11: __call__

 def __call__(self):
     self.request.response.setHeader('Content-Type', 'image/svg+xml')
     self.request.response.setHeader('Content-Disposition',
                                     'inline; filename=%s.svg' % \
                                     self.context.getId())
     tfile = tempfile.NamedTemporaryFile(suffix='.svg')
     gv = generate_gv(self.context)
     ag = AGraph(string=gv)
     ag.layout()
     ag.draw(path=tfile, format='svg', prog='dot')
     tfile.seek(0)
     return tfile.read()
开发者ID:SyZn,项目名称:collective.wfautodoc,代码行数:12,代码来源:views.py


示例12: startGraph

def startGraph():
    # We maintain this globally to make it accessible, pylint: disable=global-statement
    global graph

    if Options.shallCreateGraph():
        try:
            from pygraphviz import AGraph  # pylint: disable=I0021,import-error

            graph = AGraph(name="Optimization", directed=True)
            graph.layout()
        except ImportError:
            warning("Cannot import pygraphviz module, no graphing capability.")
开发者ID:kayhayen,项目名称:Nuitka,代码行数:12,代码来源:Graphs.py


示例13: to_dot

 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,代码行数:14,代码来源:test_stressing.py


示例14: draw_workflow

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,代码行数:11,代码来源:draw_workflow.py


示例15: run

    def run(self):
        options = self.options
        filename = self.arguments[0]
        if self.content:
            content = u'\n'.join(self.content)
            ofilename = filename + '.' + self.outputformat
        else:
            content = open(filename).read().decode(options.get('encoding','utf-8'))
            ofilename = os.path.splitext(filename)[0] + '.' + self.outputformat

        g = AGraph(string=content)
        g.layout(prog='dot')
        opath = os.path.join(OUTPUT_DIR, ofilename)
        g.draw(opath, 'png')
        self.arguments[0] = opath
        return super(GraphvizBlock, self).run()
开发者ID:yihuang,项目名称:huangyilib,代码行数:16,代码来源:graphviz_support.py


示例16: __init__

 def __init__(self, filename):
     self.G = AGraph(filename)
     xs = [(nodo, nodo.attr.get("initial", None))
           for nodo in self.G.iternodes()]
     xs = [x for x in xs if x[1]]
     if len(xs) == 0:
         raise BadInputGraph("Missing 'initial' node")
     elif len(xs) > 1:
         raise BadInputGraph("Cannot have two initial nodes")
     if not any(nodo.attr.get("goal", None) for nodo in self.G.iternodes()):
         raise BadInputGraph("Missing a goal state '[goal=\"1\"]'")
     super(DotGraphSearchProblem, self).__init__(xs[0][0])
     self.initial_state.attr["shape"] = "doublecircle"
     for node in self.G.iternodes():
         if self.is_goal(node):
             node.attr["shape"] = "hexagon"
             node.attr["color"] = "blue"
     self.seen = set()
     self.visit(self.initial_state)
     for edge in self.G.iteredges():
         edge.attr["style"] = "dotted"
         x = edge.attr.get("weight", None)
         if x:
             x = int(x)
         else:
             x = 1
         edge.attr["weight"] = x
         edge.attr["label"] = x
开发者ID:bx5974,项目名称:simpleai,代码行数:28,代码来源:dotsearch.py


示例17: render_local

 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,代码行数:13,代码来源:optimalbst.py


示例18: graph

  def graph(self, filename, reachable=True):
    from pygraphviz import AGraph # NOTE - LIS machines do not have pygraphviz
    graph = AGraph(strict=True, directed=True)

    for vertex in self.vertices.values():
      for connector in vertex.connectors:
        if not reachable or (vertex.reachable and connector.reachable):
          graphviz_connect(graph, vertex, connector)
    for connector in self.connectors.values():
      for edge in connector.edges:
        if not reachable or (connector.reachable and edge.reachable):
          graphviz_connect(graph, connector, edge)
    for edge in self.edges.values():
      for _, sink_vertex in edge.mappings:
        if not reachable or (edge.reachable and sink_vertex.reachable):
          graphviz_connect(graph, edge, sink_vertex)

    graph.draw(filename, prog='dot')
开发者ID:beomjoonkim,项目名称:openrave_repo,代码行数:18,代码来源:reachability_graph.py


示例19: build_graph

def build_graph(score):
    corpus= create_corpus(score)
    calc_tf_idf(corpus, log_tf, log_idf)

    #corpus= group_corpus(corpus, log_tf, log_idf)
    g= AGraph(strict=False)
    for i, d1 in enumerate(corpus):
        d1_name= str(d1)
        edges= [(d2, d2.similarity(d1)) for d2 in corpus[i+1:]] 
        edges.sort(key=lambda x:x[1], reverse=True)
        edges= edges[:5]
        for d2, weight in edges:
            d2_name= str(d2)
            g.add_edge(d1_name, d2_name)
            e= g.get_edge(d1_name, d2_name)
            e.attr['label']= str(weight)[:5]
   
    #import ipdb;ipdb.set_trace()
    return g
开发者ID:johndpope,项目名称:automusica,代码行数:19,代码来源:tfidf.py


示例20: __init__

    def __init__(self):
        logging.basicConfig()
        self.graph = AGraph(directed=True, strict=False)
        self.graph.node_attr["shape"] = "record"
        self.graph.graph_attr["fontsize"] = "8"
        self.graph.graph_attr["fontname"] = "Bitstream Vera Sans"
        self.graph.graph_attr["label"] = ""

        self.connected_nodes = set()
        self.described_nodes = set()
开发者ID:plt-tud,项目名称:rdf-uml-diagram,代码行数:10,代码来源:umlpygraphvizdiagram.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pygrib.open函数代码示例发布时间:2022-05-25
下一篇:
Python dot.write函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap