<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>AGraph Class — PyGraphviz v1.1.dev1952 documentation</title> <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.1.dev1952', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: false }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within PyGraphviz v1.1.dev1952 documentation" href="../_static/opensearch.xml"/> <link rel="top" title="PyGraphviz v1.1.dev1952 documentation" href="../index.html" /> <link rel="up" title="Reference" href="index.html" /> <link rel="next" title="FAQ" href="faq.html" /> <link rel="prev" title="Reference" href="index.html" /> </head> <body> <div style="color: black;background-color: white; font-size: 3.2em; text-align: left; padding: 15px 10px 10px 15px"> PyGraphviz </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="faq.html" title="FAQ" accesskey="N">next</a> |</li> <li class="right" > <a href="index.html" title="Reference" accesskey="P">previous</a> |</li> <li><a href="../index.html">PyGraphviz Home </a> | </li> <li><a href="../search.html">Search </a> | </li> <li><a href="../download.html">Download </a> | </li> <li><a href="http://networkx.lanl.gov/trac/wiki/PyGraphviz">Developer Site</a> | </li> <li><a href="../contents.html">Documentation </a> »</li> <li><a href="index.html" accesskey="U">Reference</a> »</li> </ul> </div> <p>This documentation is for version <b>1.1.dev1952</b>, which is not released yet.</p> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="index.html" title="previous chapter">Reference</a></p> <h4>Next topic</h4> <p class="topless"><a href="faq.html" title="next chapter">FAQ</a></p> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="agraph-class"> <span id="agraph"></span><h1>AGraph Class<a class="headerlink" href="#agraph-class" title="Permalink to this headline">¶</a></h1> <dl class="class"> <dt id="pygraphviz.AGraph"> <em class="property">class </em><tt class="descname">AGraph</tt><big>(</big><em>thing=None</em>, <em>filename=None</em>, <em>data=None</em>, <em>string=None</em>, <em>handle=None</em>, <em>name=''</em>, <em>strict=True</em>, <em>directed=False</em>, <em>**attr</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph" title="Permalink to this definition">¶</a></dt> <dd><p>Class for Graphviz agraph type.</p> <p>Example use</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pygraphviz</span> <span class="kn">import</span> <span class="o">*</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">directed</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="s">"file.dot"</span><span class="p">)</span> </pre></div> </div> <p>Graphviz graph keyword parameters are processed so you may add them like</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">landscape</span><span class="o">=</span><span class="s">'true'</span><span class="p">,</span><span class="n">ranksep</span><span class="o">=</span><span class="s">'0.1'</span><span class="p">)</span> </pre></div> </div> <p>or alternatively</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">graph_attr</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">landscape</span><span class="o">=</span><span class="s">'true'</span><span class="p">,</span><span class="n">ranksep</span><span class="o">=</span><span class="s">'0.1'</span><span class="p">)</span> </pre></div> </div> <p>and</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">node_attr</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="s">'red'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">edge_attr</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">len</span><span class="o">=</span><span class="s">'2.0'</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">'blue'</span><span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="http://www.graphviz.org/doc/info/attrs.html">http://www.graphviz.org/doc/info/attrs.html</a> for a list of attributes.</p> <p>Keyword parameters:</p> <p>thing is a generic input type (filename, string, handle to pointer, dictionary of dictionaries). An attempt is made to automaticaly detect the type so you may write for example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">d</span><span class="o">=</span><span class="p">{</span><span class="s">'1'</span><span class="p">:</span> <span class="p">{</span><span class="s">'2'</span><span class="p">:</span> <span class="bp">None</span><span class="p">},</span> <span class="s">'2'</span><span class="p">:</span> <span class="p">{</span><span class="s">'1'</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span> <span class="s">'3'</span><span class="p">:</span> <span class="bp">None</span><span class="p">},</span> <span class="s">'3'</span><span class="p">:</span> <span class="p">{</span><span class="s">'2'</span><span class="p">:</span> <span class="bp">None</span><span class="p">}}</span> <span class="gp">>>> </span><span class="n">A</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">s</span><span class="o">=</span><span class="n">A</span><span class="o">.</span><span class="n">to_string</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">B</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">h</span><span class="o">=</span><span class="n">B</span><span class="o">.</span><span class="n">handle</span> <span class="gp">>>> </span><span class="n">C</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">h</span><span class="p">)</span> </pre></div> </div> <p>Parameters:</p> <div class="highlight-python"><pre>name: Name for the graph strict: True|False (True for simple graphs) directed: True|False data: Dictionary of dictionaries or dictionary of lists representing nodes or edges to load into intial graph string: String containing a dot format graph handle: Swig pointer to an agraph_t data structure</pre> </div> <dl class="method"> <dt id="pygraphviz.AGraph.acyclic"> <tt class="descname">acyclic</tt><big>(</big><em>args=''</em>, <em>copy=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.acyclic" title="Permalink to this definition">¶</a></dt> <dd><p>Reverse sufficient edges in digraph to make graph acyclic. Modifies existing graph.</p> <p>To create a new graph use</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">A</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">B</span><span class="o">=</span><span class="n">A</span><span class="o">.</span><span class="n">acyclic</span><span class="p">(</span><span class="n">copy</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> </pre></div> </div> <p>See the graphviz “acyclic” program for details of the algorithm.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.add_cycle"> <tt class="descname">add_cycle</tt><big>(</big><em>nlist</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.add_cycle" title="Permalink to this definition">¶</a></dt> <dd><p>Add the cycle of nodes given in nlist.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.add_edge"> <tt class="descname">add_edge</tt><big>(</big><em>u</em>, <em>v=None</em>, <em>key=None</em>, <em>**attr</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.add_edge" title="Permalink to this definition">¶</a></dt> <dd><p>Add a single edge between nodes u and v.</p> <p>If the nodes u and v are not in the graph they will added.</p> <p>If u and v are not strings, conversion to a string will be attempted. String conversion will work if u and v have valid string representation (try str(u) if you are unsure).</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span> <span class="go">[(u'a', u'b')]</span> </pre></div> </div> <p>The optional key argument allows assignment of a key to the edge. This is especially useful to distinguish between parallel edges in multi-edge graphs (strict=False).</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">strict</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">,</span><span class="s">'first'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">,</span><span class="s">'second'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="n">keys</span><span class="o">=</span><span class="bp">True</span><span class="p">))</span> <span class="go">[(u'a', u'b', u'first'), (u'a', u'b', u'second')]</span> </pre></div> </div> <p>Attributes can be added when edges are created</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">u'a'</span><span class="p">,</span><span class="s">u'b'</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">'green'</span><span class="p">)</span> </pre></div> </div> <p>Attributes must be valid strings.</p> <p>See <a class="reference external" href="http://www.graphviz.org/doc/info/attrs.html">http://www.graphviz.org/doc/info/attrs.html</a> for a list of attributes.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.add_edges_from"> <tt class="descname">add_edges_from</tt><big>(</big><em>ebunch</em>, <em>**attr</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.add_edges_from" title="Permalink to this definition">¶</a></dt> <dd><p>Add nodes to graph from a container ebunch.</p> <p>ebunch is a container of edges such as a list or dictionary.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">elist</span><span class="o">=</span><span class="p">[(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">),(</span><span class="s">'b'</span><span class="p">,</span><span class="s">'c'</span><span class="p">)]</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">elist</span><span class="p">)</span> </pre></div> </div> <p>Attributes can be added when edges are created</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">elist</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s">'green'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.add_node"> <tt class="descname">add_node</tt><big>(</big><em>n</em>, <em>**attr</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.add_node" title="Permalink to this definition">¶</a></dt> <dd><p>Add a single node n.</p> <p>If n is not a string, conversion to a string will be attempted. String conversion will work if n has valid string representation (try str(n) if you are unsure).</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span> <span class="go">[u'a']</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c"># will be converted to a string</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span> <span class="go">[u'a', u'1']</span> </pre></div> </div> <p>Attributes can be added to nodes on creation (attribute values must be strings)</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">'red'</span><span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="http://www.graphviz.org/doc/info/attrs.html">http://www.graphviz.org/doc/info/attrs.html</a> for a list of attributes.</p> <p>Anonymous Graphviz nodes are currently not implemented.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.add_nodes_from"> <tt class="descname">add_nodes_from</tt><big>(</big><em>nbunch</em>, <em>**attr</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.add_nodes_from" title="Permalink to this definition">¶</a></dt> <dd><p>Add nodes from a container nbunch.</p> <p>nbunch can be any iterable container such as a list or dictionary</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">nlist</span><span class="o">=</span><span class="p">[</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="s">'spam'</span><span class="p">]</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">nlist</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">nodes</span><span class="p">())</span> <span class="go">[u'1', u'a', u'b', u'spam']</span> </pre></div> </div> <p>Attributes can be added to nodes on creation</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">nlist</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s">'red'</span><span class="p">)</span> <span class="c"># set all nodes in nlist red</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.add_path"> <tt class="descname">add_path</tt><big>(</big><em>nlist</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.add_path" title="Permalink to this definition">¶</a></dt> <dd><p>Add the path of nodes given in nlist.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.add_subgraph"> <tt class="descname">add_subgraph</tt><big>(</big><em>nbunch=None</em>, <em>name=None</em>, <em>**attr</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.add_subgraph" title="Permalink to this definition">¶</a></dt> <dd><p>Return subgraph induced by nodes in nbunch.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.clear"> <tt class="descname">clear</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.clear" title="Permalink to this definition">¶</a></dt> <dd><p>Remove all nodes, edges, and attributes from the graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.close"> <tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.close" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.copy"> <tt class="descname">copy</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.copy" title="Permalink to this definition">¶</a></dt> <dd><p>Return a copy of the graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.degree"> <tt class="descname">degree</tt><big>(</big><em>nbunch=None</em>, <em>with_labels=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.degree" title="Permalink to this definition">¶</a></dt> <dd><p>Return the degree of nodes given in nbunch container.</p> <p>Using optional with_labels=True returns a dictionary keyed by node with value set to the degree.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.degree_iter"> <tt class="descname">degree_iter</tt><big>(</big><em>nbunch=None</em>, <em>indeg=True</em>, <em>outdeg=True</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.degree_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over the degree of the nodes given in nbunch container.</p> <p>Returns paris of (node,degree).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.delete_edge"> <tt class="descname">delete_edge</tt><big>(</big><em>u</em>, <em>v=None</em>, <em>key=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.delete_edge" title="Permalink to this definition">¶</a></dt> <dd><p>Remove edge between nodes u and v from the graph.</p> <p>With optional key argument will only remove an edge matching (u,v,key).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.delete_edges_from"> <tt class="descname">delete_edges_from</tt><big>(</big><em>ebunch</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.delete_edges_from" title="Permalink to this definition">¶</a></dt> <dd><p>Remove edges from ebunch (a container of edges).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.delete_node"> <tt class="descname">delete_node</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.delete_node" title="Permalink to this definition">¶</a></dt> <dd><p>Remove the single node n.</p> <p>Attempting to remove a node that isn’t in the graph will produce an error.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">remove_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.delete_nodes_from"> <tt class="descname">delete_nodes_from</tt><big>(</big><em>nbunch</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.delete_nodes_from" title="Permalink to this definition">¶</a></dt> <dd><p>Remove nodes from a container nbunch.</p> <p>nbunch can be any iterable container such as a list or dictionary</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">nlist</span><span class="o">=</span><span class="p">[</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="s">'spam'</span><span class="p">]</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">nlist</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">remove_nodes_from</span><span class="p">(</span><span class="n">nlist</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.delete_subgraph"> <tt class="descname">delete_subgraph</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.delete_subgraph" title="Permalink to this definition">¶</a></dt> <dd><p>Remove subgraph with given name.</p> </dd></dl> <dl class="attribute"> <dt id="pygraphviz.AGraph.directed"> <tt class="descname">directed</tt><a class="headerlink" href="#pygraphviz.AGraph.directed" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if graph is directed or False if not.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.draw"> <tt class="descname">draw</tt><big>(</big><em>path=None</em>, <em>format=None</em>, <em>prog=None</em>, <em>args=''</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.draw" title="Permalink to this definition">¶</a></dt> <dd><p>Output graph to path in specified format.</p> <p>An attempt will be made to guess the output format based on the file extension of <cite>path</cite>. If that fails, then the <cite>format</cite> parameter will be used.</p> <p>Note, if <cite>path</cite> is a file object returned by a call to os.fdopen(), then the method for discovering the format will not work. In such cases, one should explicitly set the <cite>format</cite> parameter; otherwise, it will default to ‘dot’.</p> <p>Formats (not all may be available on every system depending on how Graphviz was built)</p> <blockquote> <div>‘canon’, ‘cmap’, ‘cmapx’, ‘cmapx_np’, ‘dia’, ‘dot’, ‘fig’, ‘gd’, ‘gd2’, ‘gif’, ‘hpgl’, ‘imap’, ‘imap_np’, ‘ismap’, ‘jpe’, ‘jpeg’, ‘jpg’, ‘mif’, ‘mp’, ‘pcl’, ‘pdf’, ‘pic’, ‘plain’, ‘plain-ext’, ‘png’, ‘ps’, ‘ps2’, ‘svg’, ‘svgz’, ‘vml’, ‘vmlz’, ‘vrml’, ‘vtx’, ‘wbmp’, ‘xdot’, ‘xlib’</div></blockquote> <p>If prog is not specified and the graph has positions (see layout()) then no additional graph positioning will be performed.</p> <p>Optional prog=[‘neato’|’dot’|’twopi’|’circo’|’fdp’|’nop’] will use specified graphviz layout method.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">layout</span><span class="p">()</span> </pre></div> </div> <p># use current node positions, output ps in ‘file.ps’ >>> G.draw(‘file.ps’)</p> <p># use dot to position, output png in ‘file’ >>> G.draw(‘file’, format=’png’,prog=’dot’)</p> <p># use keyword ‘args’ to pass additional arguments to graphviz >>> G.draw(‘test.ps’,prog=’twopi’,args=’-Gepsilon=1’)</p> <p>The layout might take a long time on large graphs.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.edges"> <tt class="descname">edges</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.edges" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of edges in the graph.</p> <p>If the optional nbunch (container of nodes) only edges adjacent to nodes in nbunch will be returned.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'c'</span><span class="p">,</span><span class="s">'d'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">())</span> <span class="go">[(u'a', u'b'), (u'c', u'd')]</span> <span class="gp">>>> </span><span class="k">print</span> <span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="go">[(u'a', u'b')]</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.edges_iter"> <tt class="descname">edges_iter</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.edges_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over out edges in the graph.</p> <p>If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.</p> <p>Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use out_edges() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.from_string"> <tt class="descname">from_string</tt><big>(</big><em>string</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.from_string" title="Permalink to this definition">¶</a></dt> <dd><p>Load a graph from a string in dot format.</p> <p>Overwrites any existing graph.</p> <p>To make a new graph from a string use</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span><span class="o">=</span><span class="s">'digraph {1 -> 2}'</span> <span class="gp">>>> </span><span class="n">A</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">t</span><span class="o">=</span><span class="n">A</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">A</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">string</span><span class="o">=</span><span class="n">s</span><span class="p">)</span> <span class="c"># specify s is a string</span> <span class="gp">>>> </span><span class="n">A</span><span class="o">=</span><span class="n">AGraph</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="c"># s assumed to be a string during initialization</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.get_edge"> <tt class="descname">get_edge</tt><big>(</big><em>u</em>, <em>v</em>, <em>key=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.get_edge" title="Permalink to this definition">¶</a></dt> <dd><p>Return an edge object (Edge) corresponding to edge (u,v).</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">edge</span><span class="o">=</span><span class="n">G</span><span class="o">.</span><span class="n">get_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="n">edge</span> <span class="go">(u'a', u'b')</span> </pre></div> </div> <p>With optional key argument will only get edge matching (u,v,key).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.get_name"> <tt class="descname">get_name</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.get_name" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.get_node"> <tt class="descname">get_node</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.get_node" title="Permalink to this definition">¶</a></dt> <dd><p>Return a node object (Node) corresponding to node n.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">node</span><span class="o">=</span><span class="n">G</span><span class="o">.</span><span class="n">get_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="n">node</span> <span class="go">a</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.get_subgraph"> <tt class="descname">get_subgraph</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.get_subgraph" title="Permalink to this definition">¶</a></dt> <dd><p>Return existing subgraph with specified name or None if it doesn’t exist.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.has_edge"> <tt class="descname">has_edge</tt><big>(</big><em>u</em>, <em>v=None</em>, <em>key=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.has_edge" title="Permalink to this definition">¶</a></dt> <dd><p>Return True an edge u-v is in the graph or False if not.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">has_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="go">True</span> </pre></div> </div> <p>Optional key argument will restrict match to edges (u,v,key).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.has_neighbor"> <tt class="descname">has_neighbor</tt><big>(</big><em>u</em>, <em>v</em>, <em>key=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.has_neighbor" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if u has an edge to v or False if not.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">has_neighbor</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">)</span> <span class="go">True</span> </pre></div> </div> <p>Optional key argument will only find edges (u,v,key).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.has_node"> <tt class="descname">has_node</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.has_node" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if n is in the graph or False if not.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">has_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="go">True</span> <span class="gp">>>> </span><span class="s">'a'</span> <span class="ow">in</span> <span class="n">G</span> <span class="c"># same as G.has_node('a')</span> <span class="go">True</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.in_degree"> <tt class="descname">in_degree</tt><big>(</big><em>nbunch=None</em>, <em>with_labels=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.in_degree" title="Permalink to this definition">¶</a></dt> <dd><p>Return the in-degree of nodes given in nbunch container.</p> <p>Using optional with_labels=True returns a dictionary keyed by node with value set to the degree.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.in_degree_iter"> <tt class="descname">in_degree_iter</tt><big>(</big><em>nbunch=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.in_degree_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over the in-degree of the nodes given in nbunch container.</p> <p>Returns paris of (node,degree).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.in_edges"> <tt class="descname">in_edges</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.in_edges" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of in edges in the graph. If the optional nbunch (container of nodes) only in edges adjacent to nodes in nbunch will be returned.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.in_edges_iter"> <tt class="descname">in_edges_iter</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.in_edges_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over out edges in the graph.</p> <p>If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.</p> <p>Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use in_edges() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.in_neighbors"> <tt class="descname">in_neighbors</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.in_neighbors" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of predecessor nodes of n.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.is_directed"> <tt class="descname">is_directed</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.is_directed" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if graph is directed or False if not.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.is_strict"> <tt class="descname">is_strict</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.is_strict" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if graph is strict or False if not.</p> <p>Strict graphs do not allow parallel edges or self loops.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.is_undirected"> <tt class="descname">is_undirected</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.is_undirected" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if graph is undirected or False if not.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iterdegree"> <tt class="descname">iterdegree</tt><big>(</big><em>nbunch=None</em>, <em>indeg=True</em>, <em>outdeg=True</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iterdegree" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over the degree of the nodes given in nbunch container.</p> <p>Returns paris of (node,degree).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iteredges"> <tt class="descname">iteredges</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iteredges" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over out edges in the graph.</p> <p>If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.</p> <p>Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use out_edges() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iterindegree"> <tt class="descname">iterindegree</tt><big>(</big><em>nbunch=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iterindegree" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over the in-degree of the nodes given in nbunch container.</p> <p>Returns paris of (node,degree).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iterinedges"> <tt class="descname">iterinedges</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iterinedges" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over out edges in the graph.</p> <p>If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.</p> <p>Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use in_edges() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iterneighbors"> <tt class="descname">iterneighbors</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iterneighbors" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over the nodes attached to n.</p> <p>Note: modifying the graph structure while iterating over node neighbors may produce unpredictable results. Use neighbors() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iternodes"> <tt class="descname">iternodes</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iternodes" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over all the nodes in the graph.</p> <p>Note: modifying the graph structure while iterating over the nodes may produce unpredictable results. Use nodes() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iteroutdegree"> <tt class="descname">iteroutdegree</tt><big>(</big><em>nbunch=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iteroutdegree" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over the out-degree of the nodes given in nbunch container.</p> <p>Returns paris of (node,degree).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iteroutedges"> <tt class="descname">iteroutedges</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iteroutedges" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over out edges in the graph.</p> <p>If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.</p> <p>Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use out_edges() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.iterpred"> <tt class="descname">iterpred</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.iterpred" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over predecessor nodes of n.</p> <p>Note: modifying the graph structure while iterating over node predecessors may produce unpredictable results. Use predecessors() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.itersucc"> <tt class="descname">itersucc</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.itersucc" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over successor nodes of n.</p> <p>Note: modifying the graph structure while iterating over node successors may produce unpredictable results. Use successors() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.layout"> <tt class="descname">layout</tt><big>(</big><em>prog='neato'</em>, <em>args=''</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.layout" title="Permalink to this definition">¶</a></dt> <dd><p>Assign positions to nodes in graph.</p> <p>Optional prog=[‘neato’|’dot’|’twopi’|’circo’|’fdp’|’nop’] will use specified graphviz layout method.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">A</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">A</span><span class="o">.</span><span class="n">layout</span><span class="p">()</span> <span class="c"># uses neato </span> <span class="gp">>>> </span><span class="n">A</span><span class="o">.</span><span class="n">layout</span><span class="p">(</span><span class="n">prog</span><span class="o">=</span><span class="s">'dot'</span><span class="p">)</span> </pre></div> </div> <p>Use keyword args to add additional arguments to graphviz programs.</p> <p>The layout might take a long time on large graphs.</p> </dd></dl> <dl class="attribute"> <dt id="pygraphviz.AGraph.name"> <tt class="descname">name</tt><a class="headerlink" href="#pygraphviz.AGraph.name" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.neighbors"> <tt class="descname">neighbors</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.neighbors" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the nodes attached to n.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.neighbors_iter"> <tt class="descname">neighbors_iter</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.neighbors_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over the nodes attached to n.</p> <p>Note: modifying the graph structure while iterating over node neighbors may produce unpredictable results. Use neighbors() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.nodes"> <tt class="descname">nodes</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.nodes" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of all nodes in the graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.nodes_iter"> <tt class="descname">nodes_iter</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.nodes_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over all the nodes in the graph.</p> <p>Note: modifying the graph structure while iterating over the nodes may produce unpredictable results. Use nodes() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.number_of_edges"> <tt class="descname">number_of_edges</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.number_of_edges" title="Permalink to this definition">¶</a></dt> <dd><p>Return the number of edges in the graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.number_of_nodes"> <tt class="descname">number_of_nodes</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.number_of_nodes" title="Permalink to this definition">¶</a></dt> <dd><p>Return the number of nodes in the graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.order"> <tt class="descname">order</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.order" title="Permalink to this definition">¶</a></dt> <dd><p>Return the number of nodes in the graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.out_degree"> <tt class="descname">out_degree</tt><big>(</big><em>nbunch=None</em>, <em>with_labels=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.out_degree" title="Permalink to this definition">¶</a></dt> <dd><p>Return the out-degree of nodes given in nbunch container.</p> <p>Using optional with_labels=True returns a dictionary keyed by node with value set to the degree.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.out_degree_iter"> <tt class="descname">out_degree_iter</tt><big>(</big><em>nbunch=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.out_degree_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over the out-degree of the nodes given in nbunch container.</p> <p>Returns paris of (node,degree).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.out_edges"> <tt class="descname">out_edges</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.out_edges" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of out edges in the graph.</p> <p>If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.out_edges_iter"> <tt class="descname">out_edges_iter</tt><big>(</big><em>nbunch=None</em>, <em>keys=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.out_edges_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over out edges in the graph.</p> <p>If the optional nbunch (container of nodes) only out edges adjacent to nodes in nbunch will be returned.</p> <p>Note: modifying the graph structure while iterating over edges may produce unpredictable results. Use out_edges() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.out_neighbors"> <tt class="descname">out_neighbors</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.out_neighbors" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of successor nodes of n.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.predecessors"> <tt class="descname">predecessors</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.predecessors" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of predecessor nodes of n.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.predecessors_iter"> <tt class="descname">predecessors_iter</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.predecessors_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over predecessor nodes of n.</p> <p>Note: modifying the graph structure while iterating over node predecessors may produce unpredictable results. Use predecessors() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.prepare_nbunch"> <tt class="descname">prepare_nbunch</tt><big>(</big><em>nbunch=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.prepare_nbunch" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.read"> <tt class="descname">read</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.read" title="Permalink to this definition">¶</a></dt> <dd><p>Read graph from dot format file on path.</p> <p>path can be a file name or file handle</p> <p>use:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">G</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">'file.dot'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.remove_edge"> <tt class="descname">remove_edge</tt><big>(</big><em>u</em>, <em>v=None</em>, <em>key=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.remove_edge" title="Permalink to this definition">¶</a></dt> <dd><p>Remove edge between nodes u and v from the graph.</p> <p>With optional key argument will only remove an edge matching (u,v,key).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.remove_edges_from"> <tt class="descname">remove_edges_from</tt><big>(</big><em>ebunch</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.remove_edges_from" title="Permalink to this definition">¶</a></dt> <dd><p>Remove edges from ebunch (a container of edges).</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.remove_node"> <tt class="descname">remove_node</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.remove_node" title="Permalink to this definition">¶</a></dt> <dd><p>Remove the single node n.</p> <p>Attempting to remove a node that isn’t in the graph will produce an error.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">remove_node</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.remove_nodes_from"> <tt class="descname">remove_nodes_from</tt><big>(</big><em>nbunch</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.remove_nodes_from" title="Permalink to this definition">¶</a></dt> <dd><p>Remove nodes from a container nbunch.</p> <p>nbunch can be any iterable container such as a list or dictionary</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">G</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">nlist</span><span class="o">=</span><span class="p">[</span><span class="s">'a'</span><span class="p">,</span><span class="s">'b'</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="s">'spam'</span><span class="p">]</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">nlist</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">G</span><span class="o">.</span><span class="n">remove_nodes_from</span><span class="p">(</span><span class="n">nlist</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.remove_subgraph"> <tt class="descname">remove_subgraph</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.remove_subgraph" title="Permalink to this definition">¶</a></dt> <dd><p>Remove subgraph with given name.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.reverse"> <tt class="descname">reverse</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.reverse" title="Permalink to this definition">¶</a></dt> <dd><p>Return copy of directed graph with edge directions reversed.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.size"> <tt class="descname">size</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.size" title="Permalink to this definition">¶</a></dt> <dd><p>Return the number of edges in the graph.</p> </dd></dl> <dl class="attribute"> <dt id="pygraphviz.AGraph.strict"> <tt class="descname">strict</tt><a class="headerlink" href="#pygraphviz.AGraph.strict" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if graph is strict or False if not.</p> <p>Strict graphs do not allow parallel edges or self loops.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.string"> <tt class="descname">string</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.string" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string (unicode) represetnation of graph in dot format.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.string_nop"> <tt class="descname">string_nop</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.string_nop" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string (unicode) representation of graph in dot format.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.subgraph"> <tt class="descname">subgraph</tt><big>(</big><em>nbunch=None</em>, <em>name=None</em>, <em>**attr</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.subgraph" title="Permalink to this definition">¶</a></dt> <dd><p>Return subgraph induced by nodes in nbunch.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.subgraph_parent"> <tt class="descname">subgraph_parent</tt><big>(</big><em>nbunch=None</em>, <em>name=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.subgraph_parent" title="Permalink to this definition">¶</a></dt> <dd><p>Return parent graph of subgraph or None if graph is root graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.subgraph_root"> <tt class="descname">subgraph_root</tt><big>(</big><em>nbunch=None</em>, <em>name=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.subgraph_root" title="Permalink to this definition">¶</a></dt> <dd><p>Return root graph of subgraph or None if graph is root graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.subgraphs"> <tt class="descname">subgraphs</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.subgraphs" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of all subgraphs in the graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.subgraphs_iter"> <tt class="descname">subgraphs_iter</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.subgraphs_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Iterator over subgraphs.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.successors"> <tt class="descname">successors</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.successors" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of successor nodes of n.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.successors_iter"> <tt class="descname">successors_iter</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.successors_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Return iterator over successor nodes of n.</p> <p>Note: modifying the graph structure while iterating over node successors may produce unpredictable results. Use successors() as an alternative.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.to_directed"> <tt class="descname">to_directed</tt><big>(</big><em>**kwds</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.to_directed" title="Permalink to this definition">¶</a></dt> <dd><p>Return directed copy of graph.</p> <p>Each undirected edge u-v is represented as two directed edges u->v and v->u.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.to_string"> <tt class="descname">to_string</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.to_string" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string (unicode) representation of graph in dot format.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.to_undirected"> <tt class="descname">to_undirected</tt><big>(</big><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.to_undirected" title="Permalink to this definition">¶</a></dt> <dd><p>Return undirected copy of graph.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.tred"> <tt class="descname">tred</tt><big>(</big><em>args=''</em>, <em>copy=False</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.tred" title="Permalink to this definition">¶</a></dt> <dd><p>Transitive reduction of graph. Modifies existing graph.</p> <p>To create a new graph use</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">A</span><span class="o">=</span><span class="n">AGraph</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">B</span><span class="o">=</span><span class="n">A</span><span class="o">.</span><span class="n">tred</span><span class="p">(</span><span class="n">copy</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> </pre></div> </div> <p>See the graphviz “tred” program for details of the algorithm.</p> </dd></dl> <dl class="method"> <dt id="pygraphviz.AGraph.write"> <tt class="descname">write</tt><big>(</big><em>path=None</em><big>)</big><a class="headerlink" href="#pygraphviz.AGraph.write" title="Permalink to this definition">¶</a></dt> <dd><p>Write graph in dot format to file on path.</p> <p>path can be a file name or file handle</p> <p>use:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">G</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">'file.dot'</span><span class="p">)</span> </pre></div> </div> </dd></dl> </dd></dl> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="faq.html" title="FAQ" >next</a> |</li> <li class="right" > <a href="index.html" title="Reference" >previous</a> |</li> <li><a href="../index.html">PyGraphviz Home </a> | </li> <li><a href="../search.html">Search </a> | </li> <li><a href="../download.html">Download </a> | </li> <li><a href="http://networkx.lanl.gov/trac/wiki/PyGraphviz">Developer Site</a> | </li> <li><a href="../contents.html">Documentation </a> »</li> <li><a href="index.html" >Reference</a> »</li> </ul> </div> <div class="footer"> © Copyright 2010, Aric Hagberg. Last updated on Jun 01, 2011. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7. </div> </body> </html>