Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
niemasd committed Mar 12, 2020
1 parent bf5b1a5 commit 114c615
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions docs/_modules/treeswift/Tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ <h1>Source code for treeswift.Tree</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="p">((</span><span class="n">leaves</span> <span class="ow">and</span> <span class="n">node</span><span class="o">.</span><span class="n">is_leaf</span><span class="p">())</span> <span class="ow">or</span> <span class="p">(</span><span class="n">internal</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">node</span><span class="o">.</span><span class="n">is_leaf</span><span class="p">()))</span> <span class="ow">and</span> <span class="p">(</span><span class="n">unlabeled</span> <span class="ow">or</span> <span class="n">node</span><span class="o">.</span><span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">):</span>
<span class="k">yield</span> <span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="n">d</span><span class="p">[</span><span class="n">node</span><span class="p">])</span></div>

<div class="viewcode-block" id="Tree.draw"><a class="viewcode-back" href="../../index.html#treeswift.Tree.draw">[docs]</a> <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show_plot</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">export_filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show_labels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">align_labels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">label_fontsize</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">start_time</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">default_color</span><span class="o">=</span><span class="s1">&#39;#000000&#39;</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<div class="viewcode-block" id="Tree.draw"><a class="viewcode-back" href="../../index.html#treeswift.Tree.draw">[docs]</a> <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show_plot</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">export_filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show_labels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">align_labels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">label_fontsize</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">start_time</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">default_color</span><span class="o">=</span><span class="s1">&#39;#000000&#39;</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">handles</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Draw this ``Tree``</span>

<span class="sd"> Args:</span>
Expand All @@ -453,6 +453,8 @@ <h1>Source code for treeswift.Tree</h1><div class="highlight"><pre>
<span class="sd"> ``default_color`` (``str``): The default color to use if a node doesn&#39;t have a ``color`` attribute</span>

<span class="sd"> ``xlabel`` (``str``): The label of the horizontal axis in the resulting plot</span>

<span class="sd"> ``handles`` (``list``): List of matplotlib ``Patch`` objects for a legend</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">matplotlib.ticker</span> <span class="kn">import</span> <span class="n">MaxNLocator</span>
Expand Down Expand Up @@ -507,7 +509,7 @@ <h1>Source code for treeswift.Tree</h1><div class="highlight"><pre>
<span class="n">ax</span><span class="o">.</span><span class="n">ticklabel_format</span><span class="p">(</span><span class="n">useOffset</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="c1"># disable +- from center</span>
<span class="n">ax</span><span class="o">.</span><span class="n">get_yaxis</span><span class="p">()</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span> <span class="c1"># hide y-axis</span>
<span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">traverse_preorder</span><span class="p">():</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="s1">&#39;color&#39;</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="s1">&#39;color&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">node</span><span class="o">.</span><span class="n">color</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">curr_color</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">color</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">curr_color</span> <span class="o">=</span> <span class="n">default_color</span>
Expand All @@ -524,11 +526,18 @@ <h1>Source code for treeswift.Tree</h1><div class="highlight"><pre>
<span class="c1"># show/export</span>
<span class="k">if</span> <span class="n">xlabel</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="n">xlabel</span><span class="p">)</span>
<span class="k">if</span> <span class="n">handles</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">legend</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">legend</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles</span><span class="o">=</span><span class="n">handles</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="s1">&#39;upper right&#39;</span><span class="p">,</span> <span class="n">bbox_to_anchor</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span>
<span class="k">if</span> <span class="n">show_plot</span><span class="p">:</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
<span class="k">if</span> <span class="n">export_filename</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">plt</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">export_filename</span><span class="p">)</span>
<span class="k">if</span> <span class="n">legend</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">plt</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">export_filename</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">plt</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">export_filename</span><span class="p">,</span> <span class="n">bbox_extra_artists</span><span class="o">=</span><span class="p">(</span><span class="n">legend</span><span class="p">,),</span> <span class="n">bbox_inches</span><span class="o">=</span><span class="s1">&#39;tight&#39;</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">orig</span><span class="p">:</span>
<span class="n">rcParams</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">orig</span><span class="p">[</span><span class="n">k</span><span class="p">]</span></div>
Expand Down
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ <h1>treeswift package<a class="headerlink" href="#treeswift-package" title="Perm

<dl class="method">
<dt id="treeswift.Tree.draw">
<code class="sig-name descname">draw</code><span class="sig-paren">(</span><em class="sig-param">show_plot=True</em>, <em class="sig-param">export_filename=None</em>, <em class="sig-param">show_labels=False</em>, <em class="sig-param">align_labels=False</em>, <em class="sig-param">label_fontsize=8</em>, <em class="sig-param">start_time=0</em>, <em class="sig-param">default_color='#000000'</em>, <em class="sig-param">xlabel=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/treeswift/Tree.html#Tree.draw"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#treeswift.Tree.draw" title="Permalink to this definition"></a></dt>
<code class="sig-name descname">draw</code><span class="sig-paren">(</span><em class="sig-param">show_plot=True</em>, <em class="sig-param">export_filename=None</em>, <em class="sig-param">show_labels=False</em>, <em class="sig-param">align_labels=False</em>, <em class="sig-param">label_fontsize=8</em>, <em class="sig-param">start_time=0</em>, <em class="sig-param">default_color='#000000'</em>, <em class="sig-param">xlabel=None</em>, <em class="sig-param">handles=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/treeswift/Tree.html#Tree.draw"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#treeswift.Tree.draw" title="Permalink to this definition"></a></dt>
<dd><p>Draw this <code class="docutils literal notranslate"><span class="pre">Tree</span></code></p>
<dl>
<dt>Args:</dt><dd><p><code class="docutils literal notranslate"><span class="pre">show_plot</span></code> (<code class="docutils literal notranslate"><span class="pre">bool</span></code>): <code class="docutils literal notranslate"><span class="pre">True</span></code> to show the plot, otherwise <code class="docutils literal notranslate"><span class="pre">False</span></code></p>
Expand All @@ -461,6 +461,7 @@ <h1>treeswift package<a class="headerlink" href="#treeswift-package" title="Perm
<p><code class="docutils literal notranslate"><span class="pre">label_fontsize</span></code> (<code class="docutils literal notranslate"><span class="pre">int</span></code>): Font size of the leaf labels (in points). 8pt = 1/9in –&gt; 1in = 72pt</p>
<p><code class="docutils literal notranslate"><span class="pre">default_color</span></code> (<code class="docutils literal notranslate"><span class="pre">str</span></code>): The default color to use if a node doesn’t have a <code class="docutils literal notranslate"><span class="pre">color</span></code> attribute</p>
<p><code class="docutils literal notranslate"><span class="pre">xlabel</span></code> (<code class="docutils literal notranslate"><span class="pre">str</span></code>): The label of the horizontal axis in the resulting plot</p>
<p><code class="docutils literal notranslate"><span class="pre">handles</span></code> (<code class="docutils literal notranslate"><span class="pre">list</span></code>): List of matplotlib <code class="docutils literal notranslate"><span class="pre">Patch</span></code> objects for a legend</p>
</dd>
</dl>
</dd></dl>
Expand Down
Loading

0 comments on commit 114c615

Please sign in to comment.