Skip to content

Commit ad52b4f

Browse files
committed
Preview for PR #18 903e8d2
1 parent 9460701 commit ad52b4f

5 files changed

Lines changed: 81 additions & 70 deletions

File tree

386 KB
Loading
59.4 KB
Loading

pr-18/_sources/notebooks/examples/legends_and_colorbars.ipynb

Lines changed: 61 additions & 55 deletions
Large diffs are not rendered by default.

pr-18/notebooks/examples/legends_and_colorbars.html

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
<meta property="og:type" content="website" />
1212
<meta property="og:url" content="notebooks/examples/legends_and_colorbars.html" />
1313
<meta property="og:site_name" content="spatialdata-plot" />
14-
<meta property="og:description" content="Every coloured plot needs a key. spatialdata-plot builds three kinds automatically: a legend for categorical colours, a colorbar for continuous ones, and a channel legend for multichannel images. s..." />
14+
<meta property="og:description" content="Every coloured plot needs a key. spatialdata-plot builds three kinds automatically: a categorical colour (named groups) gets a legend, a continuous colour (a numeric range) gets a colorbar, and a m..." />
1515
<meta property="og:image:width" content="1146" />
1616
<meta property="og:image:height" content="600" />
17-
<meta property="og:image" content="_images/social_previews/summary_notebooks_examples_legends_and_colorbars_64bcf9f2.png" />
18-
<meta property="og:image:alt" content="Every coloured plot needs a key. spatialdata-plot builds three kinds automatically: a legend for categorical colours, a colorbar for continuous ones, and a channel legend for multichannel images. s..." />
19-
<meta name="description" content="Every coloured plot needs a key. spatialdata-plot builds three kinds automatically: a legend for categorical colours, a colorbar for continuous ones, and a channel legend for multichannel images. s..." />
17+
<meta property="og:image" content="_images/social_previews/summary_notebooks_examples_legends_and_colorbars_3a18b26e.png" />
18+
<meta property="og:image:alt" content="Every coloured plot needs a key. spatialdata-plot builds three kinds automatically: a categorical colour (named groups) gets a legend, a continuous colour (a numeric range) gets a colorbar, and a m..." />
19+
<meta name="description" content="Every coloured plot needs a key. spatialdata-plot builds three kinds automatically: a categorical colour (named groups) gets a legend, a continuous colour (a numeric range) gets a colorbar, and a m..." />
2020
<meta name="twitter:card" content="summary_large_image" />
2121

2222
<title>Legends and colorbars in spatialdata-plot &#8212; spatialdata-plot</title>
@@ -431,9 +431,10 @@ <h2> Contents </h2>
431431

432432
<section class="tex2jax_ignore mathjax_ignore" id="legends-and-colorbars-in-spatialdata-plot">
433433
<h1>Legends and colorbars in spatialdata-plot<a class="headerlink" href="#legends-and-colorbars-in-spatialdata-plot" title="Link to this heading">#</a></h1>
434-
<p>Every coloured plot needs a key. <code class="docutils literal notranslate"><span class="pre">spatialdata-plot</span></code> builds three kinds automatically: a <strong>legend</strong> for
435-
categorical colours, a <strong>colorbar</strong> for continuous ones, and a <strong>channel legend</strong> for multichannel
436-
images. <code class="docutils literal notranslate"><span class="pre">show()</span></code> exposes a family of arguments to place and style each. By the end you should be able
434+
<p>Every coloured plot needs a key. <code class="docutils literal notranslate"><span class="pre">spatialdata-plot</span></code> builds three kinds automatically: a <strong>categorical</strong> colour (named groups) gets a
435+
<strong>legend</strong>, a <strong>continuous</strong> colour (a numeric range) gets a <strong>colorbar</strong>, and a multichannel image
436+
gets a <strong>channel legend</strong>. <code class="docutils literal notranslate"><span class="pre">show()</span></code> places and styles the legend and colorbar; the channel legend is
437+
switched on with <code class="docutils literal notranslate"><span class="pre">render_images(channels_as_legend=True)</span></code>. By the end you should be able
437438
to:</p>
438439
<ul class="simple">
439440
<li><p>Place a categorical legend anywhere (<code class="docutils literal notranslate"><span class="pre">legend_loc</span></code>) and restyle it (<code class="docutils literal notranslate"><span class="pre">legend_fontsize</span></code>,
@@ -544,8 +545,8 @@ <h2>3. Restyling the legend<a class="headerlink" href="#restyling-the-legend" ti
544545
</section>
545546
<section id="hiding-na-na-in-legend">
546547
<h2>4. Hiding NA — <code class="docutils literal notranslate"><span class="pre">na_in_legend</span></code><a class="headerlink" href="#hiding-na-na-in-legend" title="Link to this heading">#</a></h2>
547-
<p>When you restrict to a few <code class="docutils literal notranslate"><span class="pre">groups</span></code>, the remaining spots become NA; <code class="docutils literal notranslate"><span class="pre">na_in_legend=False</span></code> drops that
548-
entry from the key.</p>
548+
<p><code class="docutils literal notranslate"><span class="pre">groups</span></code> subsets a categorical colour to the named categories; the remaining spots become NA, and
549+
<code class="docutils literal notranslate"><span class="pre">na_in_legend=False</span></code> drops that NA entry from the key.</p>
549550
<div class="cell docutils container">
550551
<div class="cell_input docutils container">
551552
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="p">(</span>
@@ -565,6 +566,7 @@ <h2>5. Bundling options — <code class="docutils literal notranslate"><span cla
565566
<p>Instead of the flat <code class="docutils literal notranslate"><span class="pre">legend_*</span></code> kwargs you can pass one <code class="docutils literal notranslate"><span class="pre">legend_params</span></code> dict. Accepted keys:
566567
<code class="docutils literal notranslate"><span class="pre">location</span></code> (or <code class="docutils literal notranslate"><span class="pre">loc</span></code>), <code class="docutils literal notranslate"><span class="pre">fontsize</span></code>, <code class="docutils literal notranslate"><span class="pre">fontweight</span></code>, <code class="docutils literal notranslate"><span class="pre">fontoutline</span></code>, <code class="docutils literal notranslate"><span class="pre">na_in_legend</span></code>; it overrides the
567568
matching flat kwargs, and unknown keys raise an error.</p>
569+
<p>Note <code class="docutils literal notranslate"><span class="pre">legend_title</span></code> is <strong>not</strong> among the accepted keys — keep it as a flat <code class="docutils literal notranslate"><span class="pre">legend_title=</span></code> kwarg.</p>
568570
<div class="cell docutils container">
569571
<div class="cell_input docutils container">
570572
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="p">(</span>
@@ -601,21 +603,23 @@ <h2>6. Continuous colours get a colorbar<a class="headerlink" href="#continuous-
601603
</section>
602604
<section id="placing-and-styling-the-colorbar-colorbar-params">
603605
<h2>7. Placing and styling the colorbar — <code class="docutils literal notranslate"><span class="pre">colorbar_params</span></code><a class="headerlink" href="#placing-and-styling-the-colorbar-colorbar-params" title="Link to this heading">#</a></h2>
604-
<p><code class="docutils literal notranslate"><span class="pre">colorbar_params</span></code> accepts <code class="docutils literal notranslate"><span class="pre">label</span></code>, <code class="docutils literal notranslate"><span class="pre">loc</span></code>, <code class="docutils literal notranslate"><span class="pre">width</span></code>, <code class="docutils literal notranslate"><span class="pre">pad</span></code> (and matplotlib colorbar keys such as
605-
<code class="docutils literal notranslate"><span class="pre">orientation</span></code>). Move the bar below the plot and give it a label, or dock it to a different side.</p>
606+
<p><code class="docutils literal notranslate"><span class="pre">colorbar_params</span></code> accepts <code class="docutils literal notranslate"><span class="pre">label</span></code>, <code class="docutils literal notranslate"><span class="pre">loc</span></code> (position — <code class="docutils literal notranslate"><span class="pre">&quot;right&quot;</span></code> by default, or <code class="docutils literal notranslate"><span class="pre">&quot;left&quot;</span></code>/<code class="docutils literal notranslate"><span class="pre">&quot;top&quot;</span></code>/
607+
<code class="docutils literal notranslate"><span class="pre">&quot;bottom&quot;</span></code>), <code class="docutils literal notranslate"><span class="pre">width</span></code>, <code class="docutils literal notranslate"><span class="pre">pad</span></code>, plus matplotlib colorbar keys. Set <code class="docutils literal notranslate"><span class="pre">loc</span></code> to move the bar; its orientation
608+
follows the side automatically (horizontal for top/bottom). Passing only <code class="docutils literal notranslate"><span class="pre">orientation</span></code> does <strong>not</strong>
609+
move it — the bar stays docked right.</p>
606610
<div class="cell docutils container">
607611
<div class="cell_input docutils container">
608612
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="p">(</span>
609613
<span class="n">sdata</span><span class="o">.</span><span class="n">pl</span><span class="o">.</span><span class="n">render_images</span><span class="p">(</span><span class="s2">"hne"</span><span class="p">)</span>
610614
<span class="o">.</span><span class="n">pl</span><span class="o">.</span><span class="n">render_shapes</span><span class="p">(</span><span class="s2">"spots"</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s2">"total_counts"</span><span class="p">)</span>
611615
<span class="p">)</span><span class="o">.</span><span class="n">pl</span><span class="o">.</span><span class="n">show</span><span class="p">(</span>
612-
<span class="n">colorbar_params</span><span class="o">=</span><span class="p">{</span><span class="s2">"label"</span><span class="p">:</span> <span class="s2">"Total counts"</span><span class="p">,</span> <span class="s2">"orientation"</span><span class="p">:</span> <span class="s2">"horizontal"</span><span class="p">},</span>
616+
<span class="n">colorbar_params</span><span class="o">=</span><span class="p">{</span><span class="s2">"loc"</span><span class="p">:</span> <span class="s2">"bottom"</span><span class="p">,</span> <span class="s2">"label"</span><span class="p">:</span> <span class="s2">"Total counts"</span><span class="p">},</span>
613617
<span class="p">)</span>
614618
</pre></div>
615619
</div>
616620
</div>
617621
<div class="cell_output docutils container">
618-
<img alt="../../_images/98929f0af7e435228349c848d67f194ed1d15963a46b73f40fc85f3dcd633e0d.png" src="../../_images/98929f0af7e435228349c848d67f194ed1d15963a46b73f40fc85f3dcd633e0d.png" />
622+
<img alt="../../_images/f7619084b49ae7a0ef632f127a615f0d8293327824f01e06e0651de5b0c1b851.png" src="../../_images/f7619084b49ae7a0ef632f127a615f0d8293327824f01e06e0651de5b0c1b851.png" />
619623
</div>
620624
</div>
621625
</section>
@@ -672,7 +676,8 @@ <h2>Summary<a class="headerlink" href="#summary" title="Link to this heading">#<
672676
<li><p>Place the legend with <code class="docutils literal notranslate"><span class="pre">legend_loc</span></code> (matplotlib locations <em>or</em> <code class="docutils literal notranslate"><span class="pre">&quot;right</span> <span class="pre">margin&quot;</span></code>), and style it with
673677
<code class="docutils literal notranslate"><span class="pre">legend_fontsize</span></code>/<code class="docutils literal notranslate"><span class="pre">fontweight</span></code>/<code class="docutils literal notranslate"><span class="pre">fontoutline</span></code>, <code class="docutils literal notranslate"><span class="pre">legend_title</span></code>, <code class="docutils literal notranslate"><span class="pre">na_in_legend</span></code>; or bundle in
674678
<code class="docutils literal notranslate"><span class="pre">legend_params</span></code>.</p></li>
675-
<li><p>Place and style the colorbar with <code class="docutils literal notranslate"><span class="pre">colorbar_params</span></code> (<code class="docutils literal notranslate"><span class="pre">label</span></code>, <code class="docutils literal notranslate"><span class="pre">loc</span></code>, <code class="docutils literal notranslate"><span class="pre">width</span></code>, <code class="docutils literal notranslate"><span class="pre">pad</span></code>, <code class="docutils literal notranslate"><span class="pre">orientation</span></code>).</p></li>
679+
<li><p>Place and style the colorbar with <code class="docutils literal notranslate"><span class="pre">colorbar_params</span></code>; <code class="docutils literal notranslate"><span class="pre">loc</span></code> (<code class="docutils literal notranslate"><span class="pre">&quot;right&quot;</span></code>/<code class="docutils literal notranslate"><span class="pre">&quot;left&quot;</span></code>/<code class="docutils literal notranslate"><span class="pre">&quot;top&quot;</span></code>/<code class="docutils literal notranslate"><span class="pre">&quot;bottom&quot;</span></code>)
680+
sets its position and the orientation follows.</p></li>
676681
<li><p>In a multi-panel <code class="docutils literal notranslate"><span class="pre">color=[...]</span></code> figure each panel gets the appropriate key.</p></li>
677682
</ul>
678683
</section>

pr-18/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)