How to use pygraphviz - 10 common examples

To help you get started, we’ve selected a few pygraphviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github albertmeronyo / ConceptDrift / src / conceptDrift.py View on Github external
SELECT DISTINCT ?parent ?node
FROM 
WHERE {
?node skos:broader ?parent
} ORDER BY ?parent
""")

resultsEdges = sparql.query().convert()

for y in resultsEdges["results"]["bindings"]:
    g1.add_edge(("/".join(y["parent"]["value"].split("/")[5:]), "/".join(y["node"]["value"].split("/")[5:])))

# Draw as PNG
# print "Writing plot..."
dot = write(g1)
G = pgv.AGraph(dot)
G.layout(prog='dot')
G.draw('../output/foo.png')
print G.string()
# gvv = gv.readstring(dot)
github c30ra / uv-align-distribute / uv_align_distribute / networkx / networkx / drawing / nx_agraph.py View on Github external
>>> pos = nx.nx_agraph.graphviz_layout(G)
    >>> pos = nx.nx_agraph.graphviz_layout(G, prog='dot')

    """
    try:
        import pygraphviz
    except ImportError:
        raise ImportError('requires pygraphviz ',
                          'http://pygraphviz.github.io/')
    if root is not None:
        args+="-Groot=%s"%root
    A=to_agraph(G)
    A.layout(prog=prog,args=args)
    node_pos={}
    for n in G:
        node=pygraphviz.Node(A,n)
        try:
            xx,yy=node.attr["pos"].split(',')
            node_pos[n]=(float(xx),float(yy))
        except:
            print("no position for node",n)
            node_pos[n]=(0.0,0.0)
    return node_pos

github prismmodelchecker / prism-games / prism-examples / smg / car / networkx / drawing / nx_agraph.py View on Github external
>>> pos=nx.graphviz_layout(G,prog='dot')

    """
    try:
        import pygraphviz
    except ImportError:
        raise ImportError('requires pygraphviz ',
                          'http://networkx.lanl.gov/pygraphviz ',
                          '(not available for Python3)')
    if root is not None:
        args+="-Groot=%s"%root
    A=to_agraph(G)
    A.layout(prog=prog,args=args)
    node_pos={}
    for n in G:
        node=pygraphviz.Node(A,n)
        try:
            xx,yy=node.attr["pos"].split(',')
            node_pos[n]=(float(xx),float(yy))
        except:
            print("no position for node",n)
            node_pos[n]=(0.0,0.0)
    return node_pos
github SpaceGroupUCL / qgisSpaceSyntaxToolkit / esstoolkit / external / networkx / drawing / nx_agraph.py View on Github external
>>> pos = nx.nx_agraph.graphviz_layout(G)
    >>> pos = nx.nx_agraph.graphviz_layout(G, prog='dot')

    """
    try:
        import pygraphviz
    except ImportError:
        raise ImportError('requires pygraphviz ',
                          'http://pygraphviz.github.io/')
    if root is not None:
        args+="-Groot=%s"%root
    A=to_agraph(G)
    A.layout(prog=prog,args=args)
    node_pos={}
    for n in G:
        node=pygraphviz.Node(A,n)
        try:
            xx,yy=node.attr["pos"].split(',')
            node_pos[n]=(float(xx),float(yy))
        except:
            print("no position for node",n)
            node_pos[n]=(0.0,0.0)
    return node_pos
github networkx / networkx / networkx / drawing / nx_agraph.py View on Github external
H_layout = nx.nx_agraph.pygraphviz_layout(G, prog='dot')
        G_layout = {H.nodes[n]['node_label']: p for n, p in H_layout.items()}

    """
    try:
        import pygraphviz
    except ImportError:
        raise ImportError('requires pygraphviz ',
                          'http://pygraphviz.github.io/')
    if root is not None:
        args += "-Groot=%s" % root
    A = to_agraph(G)
    A.layout(prog=prog, args=args)
    node_pos = {}
    for n in G:
        node = pygraphviz.Node(A, n)
        try:
            xs = node.attr["pos"].split(',')
            node_pos[n] = tuple(float(x) for x in xs)
        except:
            print("no position for node", n)
            node_pos[n] = (0.0, 0.0)
    return node_pos
github cogeorg / BlackRhino / networkx / drawing / nx_agraph.py View on Github external
>>> pos = nx.nx_agraph.graphviz_layout(G)
    >>> pos = nx.nx_agraph.graphviz_layout(G, prog='dot')

    """
    try:
        import pygraphviz
    except ImportError:
        raise ImportError('requires pygraphviz ',
                          'http://pygraphviz.github.io/')
    if root is not None:
        args+="-Groot=%s"%root
    A=to_agraph(G)
    A.layout(prog=prog,args=args)
    node_pos={}
    for n in G:
        node=pygraphviz.Node(A,n)
        try:
            xx,yy=node.attr["pos"].split(',')
            node_pos[n]=(float(xx),float(yy))
        except:
            print("no position for node",n)
            node_pos[n]=(0.0,0.0)
    return node_pos
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
runprog=r'"%s"'%self._get_prog(prog)
        cmd=' '.join([runprog,args])
        dotargs = shlex.split(cmd)
        p = subprocess.Popen(dotargs,
                             shell=False,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             close_fds=False)
        (child_stdin,
         child_stdout,
         child_stderr) = (p.stdin, p.stdout, p.stderr)
        # Use threading to avoid blocking
        data = []
        errors = []
        threads = [PipeReader(data, child_stdout),
                   PipeReader(errors, child_stderr)]
        for t in threads:
            t.start()
        self.write(child_stdin)
        child_stdin.close()
        for t in threads:
            t.join()

        if data==[]:
            raise IOError(b''.join(errors))

        if len(errors)>0:
            warnings.warn(b''.join(errors),RuntimeWarning)

        return b"".join(data)
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
cmd = ' '.join([runprog, args])
        dotargs = shlex.split(cmd)
        p = subprocess.Popen(dotargs,
                             shell=False,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             close_fds=False)
        (child_stdin,
         child_stdout,
         child_stderr) = (p.stdin, p.stdout, p.stderr)
        # Use threading to avoid blocking
        data = []
        errors = []
        threads = [PipeReader(data, child_stdout),
                   PipeReader(errors, child_stderr)]
        for t in threads:
            t.start()

        self.write(child_stdin)
        child_stdin.close()

        for t in threads:
            t.join()
        p.wait()

        if not data:
            raise IOError(b"".join(errors).decode(self.encoding))

        if len(errors) > 0:
            warnings.warn(b"".join(errors).decode(self.encoding), RuntimeWarning)
        return b"".join(data)
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
cmd=' '.join([runprog,args])
        dotargs = shlex.split(cmd)
        p = subprocess.Popen(dotargs,
                             shell=False,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             close_fds=False)
        (child_stdin,
         child_stdout,
         child_stderr) = (p.stdin, p.stdout, p.stderr)
        # Use threading to avoid blocking
        data = []
        errors = []
        threads = [PipeReader(data, child_stdout),
                   PipeReader(errors, child_stderr)]
        for t in threads:
            t.start()
        self.write(child_stdin)
        child_stdin.close()
        for t in threads:
            t.join()

        if data==[]:
            raise IOError(b''.join(errors))

        if len(errors)>0:
            warnings.warn(b''.join(errors),RuntimeWarning)

        return b"".join(data)
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
runprog = r'"%s"' % self._get_prog(prog)
        cmd = ' '.join([runprog, args])
        dotargs = shlex.split(cmd)
        p = subprocess.Popen(dotargs,
                             shell=False,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             close_fds=False)
        (child_stdin,
         child_stdout,
         child_stderr) = (p.stdin, p.stdout, p.stderr)
        # Use threading to avoid blocking
        data = []
        errors = []
        threads = [PipeReader(data, child_stdout),
                   PipeReader(errors, child_stderr)]
        for t in threads:
            t.start()

        self.write(child_stdin)
        child_stdin.close()

        for t in threads:
            t.join()
        p.wait()

        if not data:
            raise IOError(b"".join(errors).decode(self.encoding))

        if len(errors) > 0:
            warnings.warn(b"".join(errors).decode(self.encoding), RuntimeWarning)