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


Python AGraph.nodes方法代码示例

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


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

示例1: build_graph

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import nodes [as 别名]
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,代码行数:9,代码来源:graph.py

示例2: get_graphviz

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

示例3: igraph_from_dot

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import nodes [as 别名]
def igraph_from_dot(file):
    """numbered_graph(file) -> graph

  Input:
    file: the name of the dot-file 

  Output:
    graph: igraph.Graph object. Verticies has the attribute
         "name".
    """
    print("Step 1/3: Reading from dot.")
    a=AGraph(file)
    vertices = a.nodes()
    edges = a.edges()
    numbered_edges = []
    print("Step 2/3: To numbered graph. Be patient...")
    for x, y in edges:
        xx = vertices.index(x)
        yy = vertices.index(y)
        numbered_edges.append((xx,yy))
    print("Step 3/3: To igraph.")
    g=igraph.Graph(len(vertices), numbered_edges)
    g.vs["name"]=vertices
    return g
开发者ID:horvatha,项目名称:cxnet,代码行数:26,代码来源:igraphtools.py

示例4: dot_layout

# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import nodes [as 别名]
def dot_layout(cy_elements, edge_labels=False, subgraph_boxes=False, node_gt=None):
    """
    Get a CyElements object and augment it (in-place) with positions,
    widths, heights, and spline data from a dot based layout.

    edge_labels is true if labels should appear on edges
    subgraph_boxes is true if boxes should be drawn around subgraphs

    Returns the object.
    """
    elements = cy_elements.elements

    #    g = AGraph(directed=True, strict=False)
    g = AGraph(directed=True, strict=False, forcelabels=True)

    # make transitive relations appear top to bottom

    elements = list(elements)
    nodes_by_id = dict((e["data"]["id"], e) for e in elements if e["group"] == "nodes")
    order = [
        (nodes_by_id[e["data"]["source"]], nodes_by_id[e["data"]["target"]])
        for e in elements
        if e["group"] == "edges" and "transitive" in e["data"] and e["data"]["transitive"]
    ]
    elements = topological_sort(elements, order, lambda e: e["data"]["id"])

    # get the node id's and stable sort them by cluster
    # the idea here is to convert the graph into a dag by sorting
    # the nodes, then reversing the back edges. In particular, we try to make
    # all the edges between two clusters go in the same direction so clustering
    # doesn't result in horizontal edges, which dot renders badly.

    sorted_nodes = [e["data"]["id"] for e in elements if e["group"] == "nodes"]
    sorted_nodes = sorted(enumerate(sorted_nodes), key=lambda x: (nodes_by_id[x[1]]["data"]["cluster"], x[0]))
    sorted_nodes = [y for idx, y in sorted_nodes]
    node_key = dict((id, idx) for idx, id in enumerate(sorted_nodes))

    if node_gt is None:
        node_gt = lambda X, y: False
    else:
        node_gt = lambda x, y: node_key[x] > node_key[y]

    # add nodes to the graph
    for e in elements:
        if e["group"] == "nodes" and e["classes"] != "non_existing":
            g.add_node(e["data"]["id"], label=e["data"]["label"].replace("\n", "\\n"))

    # TODO: remove this, it's specific to leader_demo
    weight = {"reach": 10, "le": 10, "id": 1}
    constraint = {"pending": False}

    # add edges to the graph
    for e in elements:
        if e["group"] == "edges":
            #            kwargs = {'weight': weight.get(e["data"]["obj"], 0)},
            kwargs = {"label": e["data"]["label"]} if edge_labels else {}
            if node_gt(e["data"]["source"], e["data"]["target"]):
                g.add_edge(
                    e["data"]["target"],
                    e["data"]["source"],
                    e["data"]["id"],
                    dir="back",
                    **kwargs
                    # constraint=constraint.get(e["data"]["obj"], True),
                )
            else:
                g.add_edge(
                    e["data"]["source"],
                    e["data"]["target"],
                    e["data"]["id"],
                    **kwargs
                    # constraint=constraint.get(e["data"]["obj"], True),
                )

    # add clusters
    clusters = defaultdict(list)
    for e in elements:
        if e["group"] == "nodes" and e["data"]["cluster"] is not None and e["classes"] != "non_existing":
            clusters[e["data"]["cluster"]].append(e["data"]["id"])
    for i, k in enumerate(sorted(clusters.keys())):
        g.add_subgraph(name="cluster_{}".format(i), nbunch=clusters[k], rank="min")

    # now get positions, heights, widths, and bsplines
    g.layout(prog="dot")

    # get the y origin. we want the top left of the graph to be a
    # fixed coordinate (hopefully (0,0)) so the graph doesn't jump when
    # its height changes. Unfortunately, pygraphviz has a bug a gives
    # the wrong bbox, so we compute the max y coord.

    #    bbox = pygraphviz.graphviz.agget(g.handle,'bb')

    global y_origin
    y_origin = 0.0
    for n in g.nodes():
        top = float(n.attr["pos"].split(",")[1]) + float(n.attr["height"]) / 2
        if top > y_origin:
            y_origin = top
    if subgraph_boxes:
        for sg in g.subgraphs():
#.........这里部分代码省略.........
开发者ID:odedp,项目名称:ivy,代码行数:103,代码来源:dot_layout.py


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