Skip to content

Commit

Permalink
update anno_img:
Browse files Browse the repository at this point in the history
(1). support missing value
(2). automatically resize to the minimal sizes
(3) fix bug about invert and order of images
  • Loading branch information
DingWB committed Apr 19, 2024
1 parent 8c38982 commit 018a9d0
Show file tree
Hide file tree
Showing 56 changed files with 813 additions and 811 deletions.
19 changes: 10 additions & 9 deletions PyComplexHeatmap/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ def _calculate_cmap(self):

def _type_specific_params(self):
if self.ylim is None:
Max = np.nanmax(self.df.values)
Min = np.nanmin(self.df.values)
Max = np.nanmax(self.df.sum(axis=1).values)
Min = np.nanmin(self.df.sum(axis=1).values)
gap = Max - Min
self.ylim = [Min - 0.02 * gap, Max + 0.02 * gap]
self.ylim = [Min - 0.05 * gap, Max + 0.05 * gap]

def reorder(self, idx):
# Before plotting, df needs to be reordered according to the new clustered order.
Expand Down Expand Up @@ -557,6 +557,7 @@ def _calculate_cmap(self):

def _type_specific_params(self):
pass

def plot(self, ax=None, axis=1): # add self.gs,self.fig,self.ax,self.axes
self.axis = axis
if self.orientation is None:
Expand Down Expand Up @@ -871,10 +872,10 @@ def _calculate_cmap(self):

def _type_specific_params(self):
if self.ylim is None:
Max = np.nanmax(self.df.values)
Min = np.nanmin(self.df.values)
Max = np.nanmax(self.df.sum(axis=1).values)
Min = np.nanmin(self.df.sum(axis=1).values)
gap = Max - Min
self.ylim = [Min - 0.02 * gap, Max + 0.02 * gap]
self.ylim = [Min - 0.05 * gap, Max + 0.05 * gap]
if self.ncols > 1:
self.stacked = True
else:
Expand Down Expand Up @@ -996,11 +997,11 @@ def _calculate_cmap(self):
self.set_legend(False)

def _type_specific_params(self):
Max = np.nanmax(self.df.values)
Min = np.nanmin(self.df.values)
Max = np.nanmax(self.df.sum(axis=1).values)
Min = np.nanmin(self.df.sum(axis=1).values)
self.gap = Max - Min
if self.ylim is None:
self.ylim = [Min - 0.02 * self.gap, Max + 0.02 * self.gap]
self.ylim = [Min - 0.05 * self.gap, Max + 0.05 * self.gap]

def plot(self, ax=None, axis=1): # add self.gs,self.fig,self.ax,self.axes
if ax is None:
Expand Down
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
324 changes: 162 additions & 162 deletions docs/build/doctrees/nbsphinx/notebooks/advanced_usage.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_12_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_14_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_16_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_19_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_23_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_25_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_27_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_28_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_30_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_32_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_33_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_36_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_44_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_46_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_47_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_49_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_51_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_5_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/nbsphinx/notebooks_advanced_usage_7_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/doctrees/notebooks/advanced_usage.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/notebooks/gene_enrichment_analysis.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/notebooks/kwargs.doctree
Binary file not shown.
Binary file modified docs/build/html/_images/notebooks_advanced_usage_10_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/html/_images/notebooks_advanced_usage_12_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/html/_images/notebooks_advanced_usage_14_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/html/_images/notebooks_advanced_usage_16_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/build/html/_images/notebooks_advanced_usage_18_1.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_19_1.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_23_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_25_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_27_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_28_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_30_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_32_1.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_33_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_36_1.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_44_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_46_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_47_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_49_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_51_0.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_5_1.png
Binary file modified docs/build/html/_images/notebooks_advanced_usage_7_1.png
19 changes: 10 additions & 9 deletions docs/build/html/_modules/PyComplexHeatmap/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,10 @@ <h1>Source code for PyComplexHeatmap.annotations</h1><div class="highlight"><pre

<span class="k">def</span> <span class="nf">_type_specific_params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">Max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">gap</span> <span class="o">=</span> <span class="n">Max</span> <span class="o">-</span> <span class="n">Min</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="o">=</span> <span class="p">[</span><span class="n">Min</span> <span class="o">-</span> <span class="mf">0.02</span> <span class="o">*</span> <span class="n">gap</span><span class="p">,</span> <span class="n">Max</span> <span class="o">+</span> <span class="mf">0.02</span> <span class="o">*</span> <span class="n">gap</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="o">=</span> <span class="p">[</span><span class="n">Min</span> <span class="o">-</span> <span class="mf">0.05</span> <span class="o">*</span> <span class="n">gap</span><span class="p">,</span> <span class="n">Max</span> <span class="o">+</span> <span class="mf">0.05</span> <span class="o">*</span> <span class="n">gap</span><span class="p">]</span>

<div class="viewcode-block" id="AnnotationBase.reorder"><a class="viewcode-back" href="../../PyComplexHeatmap.annotations.html#PyComplexHeatmap.annotations.AnnotationBase.reorder">[docs]</a> <span class="k">def</span> <span class="nf">reorder</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">idx</span><span class="p">):</span>
<span class="c1"># Before plotting, df needs to be reordered according to the new clustered order.</span>
Expand Down Expand Up @@ -905,6 +905,7 @@ <h1>Source code for PyComplexHeatmap.annotations</h1><div class="highlight"><pre

<span class="k">def</span> <span class="nf">_type_specific_params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">pass</span>

<div class="viewcode-block" id="anno_label.plot"><a class="viewcode-back" href="../../PyComplexHeatmap.annotations.html#PyComplexHeatmap.annotations.anno_label.plot">[docs]</a> <span class="k">def</span> <span class="nf">plot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span> <span class="c1"># add self.gs,self.fig,self.ax,self.axes</span>
<span class="bp">self</span><span class="o">.</span><span class="n">axis</span> <span class="o">=</span> <span class="n">axis</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">orientation</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Expand Down Expand Up @@ -1219,10 +1220,10 @@ <h1>Source code for PyComplexHeatmap.annotations</h1><div class="highlight"><pre

<span class="k">def</span> <span class="nf">_type_specific_params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">Max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">gap</span> <span class="o">=</span> <span class="n">Max</span> <span class="o">-</span> <span class="n">Min</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="o">=</span> <span class="p">[</span><span class="n">Min</span> <span class="o">-</span> <span class="mf">0.02</span> <span class="o">*</span> <span class="n">gap</span><span class="p">,</span> <span class="n">Max</span> <span class="o">+</span> <span class="mf">0.02</span> <span class="o">*</span> <span class="n">gap</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="o">=</span> <span class="p">[</span><span class="n">Min</span> <span class="o">-</span> <span class="mf">0.05</span> <span class="o">*</span> <span class="n">gap</span><span class="p">,</span> <span class="n">Max</span> <span class="o">+</span> <span class="mf">0.05</span> <span class="o">*</span> <span class="n">gap</span><span class="p">]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncols</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stacked</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
Expand Down Expand Up @@ -1344,11 +1345,11 @@ <h1>Source code for PyComplexHeatmap.annotations</h1><div class="highlight"><pre
<span class="bp">self</span><span class="o">.</span><span class="n">set_legend</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_type_specific_params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">Max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">Min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">gap</span> <span class="o">=</span> <span class="n">Max</span> <span class="o">-</span> <span class="n">Min</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="o">=</span> <span class="p">[</span><span class="n">Min</span> <span class="o">-</span> <span class="mf">0.02</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">gap</span><span class="p">,</span> <span class="n">Max</span> <span class="o">+</span> <span class="mf">0.02</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">gap</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ylim</span> <span class="o">=</span> <span class="p">[</span><span class="n">Min</span> <span class="o">-</span> <span class="mf">0.05</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">gap</span><span class="p">,</span> <span class="n">Max</span> <span class="o">+</span> <span class="mf">0.05</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">gap</span><span class="p">]</span>

<div class="viewcode-block" id="anno_scatterplot.plot"><a class="viewcode-back" href="../../PyComplexHeatmap.annotations.html#PyComplexHeatmap.annotations.anno_scatterplot.plot">[docs]</a> <span class="k">def</span> <span class="nf">plot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span> <span class="c1"># add self.gs,self.fig,self.ax,self.axes</span>
<span class="k">if</span> <span class="n">ax</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Expand Down
324 changes: 162 additions & 162 deletions docs/build/html/_sources/notebooks/advanced_usage.ipynb.txt

Large diffs are not rendered by default.

Loading

0 comments on commit 018a9d0

Please sign in to comment.