Skip to content

Commit

Permalink
updates for 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Aug 27, 2022
1 parent 70f4955 commit d060463
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
Binary file modified docs/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/.doctrees/main/cell_color.doctree
Binary file not shown.
14 changes: 6 additions & 8 deletions docs/_sources/main/cell_color.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ must return a RGBA array (0-255) or a standard color name.
# set a continuous colormap to the "sepal_length" column
@table.foreground_colormap("sepal_length")
def f(v):
i = (v - 4) / 4
return [255, 0, int(255 * i), 255]
def _(x: float):
red = np.array([255, 0, 0, 255], dtype=np.uint8)
blue = np.array([0, 0, 255, 255], dtype=np.uint8)
return (x - lmin) / lrange * blue + (lmax - x) / lrange * red
.. code-block:: python
# set a discrete colormap to the "sepal_width" column
@table.background_colormap("sepal_width")
def f(v):
if v < 3.2:
return "green"
else:
return "purple"
def _(x: float):
return "green" if x < 3.2 else "violet"
.. image:: ../fig/colormap.png
14 changes: 6 additions & 8 deletions docs/main/cell_color.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,16 @@ <h1>Set Cell Colors<a class="headerlink" href="#set-cell-colors" title="Permalin
must return a RGBA array (0-255) or a standard color name.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># set a continuous colormap to the &quot;sepal_length&quot; column</span>
<span class="nd">@table</span><span class="o">.</span><span class="n">foreground_colormap</span><span class="p">(</span><span class="s2">&quot;sepal_length&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">v</span><span class="p">):</span>
<span class="n">i</span> <span class="o">=</span> <span class="p">(</span><span class="n">v</span> <span class="o">-</span> <span class="mi">4</span><span class="p">)</span> <span class="o">/</span> <span class="mi">4</span>
<span class="k">return</span> <span class="p">[</span><span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="mi">255</span> <span class="o">*</span> <span class="n">i</span><span class="p">),</span> <span class="mi">255</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_</span><span class="p">(</span><span class="n">x</span><span class="p">:</span> <span class="nb">float</span><span class="p">):</span>
<span class="n">red</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">255</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>
<span class="n">blue</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">lmin</span><span class="p">)</span> <span class="o">/</span> <span class="n">lrange</span> <span class="o">*</span> <span class="n">blue</span> <span class="o">+</span> <span class="p">(</span><span class="n">lmax</span> <span class="o">-</span> <span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="n">lrange</span> <span class="o">*</span> <span class="n">red</span>
</pre></div>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># set a discrete colormap to the &quot;sepal_width&quot; column</span>
<span class="nd">@table</span><span class="o">.</span><span class="n">background_colormap</span><span class="p">(</span><span class="s2">&quot;sepal_width&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">v</span><span class="p">):</span>
<span class="k">if</span> <span class="n">v</span> <span class="o">&lt;</span> <span class="mf">3.2</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;green&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;purple&quot;</span>
<span class="k">def</span> <span class="nf">_</span><span class="p">(</span><span class="n">x</span><span class="p">:</span> <span class="nb">float</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">&quot;green&quot;</span> <span class="k">if</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mf">3.2</span> <span class="k">else</span> <span class="s2">&quot;violet&quot;</span>
</pre></div>
</div>
<img alt="../_images/colormap.png" src="../_images/colormap.png" />
Expand Down
Loading

0 comments on commit d060463

Please sign in to comment.