Skip to content

Commit

Permalink
Update ver 0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ponnhide committed Apr 18, 2022
1 parent 760aeb1 commit 0b13f19
Show file tree
Hide file tree
Showing 9 changed files with 655 additions and 245 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ If you want to use developmental version, it can be installed using the followin
`pip install git+https://github.com/ponnhide/patchworklib.git`

## News
#### 04182022: Version 0.4.1 is released.
- `load_seaborngrid` can accepts a `seaborn.clustermap` plot. For details, see example code on [Google colab](https://colab.research.google.com/drive/1wQQyBHLNXJ5Ks6ev88IjXhGfT98SGJuM?usp=sharing)
- Some bugs were fixed.

#### 03272022: Version 0.4.0 is released.
- Add docstring for each method and class
- Add some new methods of `patchworklib.Bricks` class to set common label, title, spine and colorbar for `Brick` objets in the `Bricks` object.
Expand Down
187 changes: 187 additions & 0 deletions example/clutermap.ipynb

Large diffs are not rendered by default.

32 changes: 12 additions & 20 deletions example/seaborn_ggplot.ipynb

Large diffs are not rendered by default.

38 changes: 23 additions & 15 deletions example/seaborn_grid.ipynb

Large diffs are not rendered by default.

60 changes: 34 additions & 26 deletions example/stack.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions example/sup_elements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
{
"data": {
"text/plain": [
"<matplotlib.spines.Spine at 0x12231eac0>"
"<matplotlib.spines.Spine at 0x148651310>"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -195,7 +195,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -209,7 +209,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.9.9"
}
},
"nbformat": 4,
Expand Down
304 changes: 152 additions & 152 deletions example/tutorial.ipynb

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions patchworklib/modified_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import gridspec
from itertools import product

import seaborn
from inspect import signature
from seaborn.axisgrid import FacetGrid, JointGrid, PairGrid, Grid
import seaborn.matrix as sm
from seaborn.matrix import ClusterGrid
from seaborn._core import VectorPlotter, variable_type, categorical_order
from seaborn import utils
from seaborn.utils import _check_argument, adjust_legend_subtitles, _draw_figure
Expand Down Expand Up @@ -461,3 +464,114 @@ def __setattr_for_clustergrid__(self, key, value):
else:
super.__setattr__(self, key, value)

def __init_for_clustergrid__(self, data, pivot_kws=None, z_score=None, standard_scale=None,
figsize=None, row_colors=None, col_colors=None, mask=None,
dendrogram_ratio=None, colors_ratio=None, cbar_pos=None):
"""Grid object for organizing clustered heatmap input on to axes"""
try:
import scipy
except:
raise RuntimeError("ClusterGrid requires scipy to be available")

if isinstance(data, pd.DataFrame):
self.data = data
else:
self.data = pd.DataFrame(data)

self.data2d = self.format_data(self.data, pivot_kws, z_score,
standard_scale)

self.mask = sm._matrix_mask(self.data2d, mask)

self._figure = Grid._figure #Modified by Hideto
self._figsize = figsize
self._figure.set_size_inches(figsize)
#self._figure = plt.figure(figsize=figsize)

self.row_colors, self.row_color_labels = \
self._preprocess_colors(data, row_colors, axis=0)
self.col_colors, self.col_color_labels = \
self._preprocess_colors(data, col_colors, axis=1)

try:
row_dendrogram_ratio, col_dendrogram_ratio = dendrogram_ratio
except TypeError:
row_dendrogram_ratio = col_dendrogram_ratio = dendrogram_ratio

try:
row_colors_ratio, col_colors_ratio = colors_ratio
except TypeError:
row_colors_ratio = col_colors_ratio = colors_ratio

width_ratios = self.dim_ratios(self.row_colors,
row_dendrogram_ratio,
row_colors_ratio)
height_ratios = self.dim_ratios(self.col_colors,
col_dendrogram_ratio,
col_colors_ratio)

nrows = 2 if self.col_colors is None else 3
ncols = 2 if self.row_colors is None else 3

self.gs = gridspec.GridSpec(nrows, ncols,
width_ratios=width_ratios,
height_ratios=height_ratios, wspace=0, hspace=0)

self.ax_row_dendrogram = self._figure.add_subplot(self.gs[-1, 0])
self.ax_col_dendrogram = self._figure.add_subplot(self.gs[0, -1])
self.ax_row_dendrogram.set_axis_off()
self.ax_col_dendrogram.set_axis_off()

self.ax_row_colors = None
self.ax_col_colors = None

if self.row_colors is not None:
self.ax_row_colors = self._figure.add_subplot(
self.gs[-1, 1])
if self.col_colors is not None:
self.ax_col_colors = self._figure.add_subplot(
self.gs[1, -1])

self.ax_heatmap = self._figure.add_subplot(self.gs[-1, -1])
if cbar_pos is None:
self.ax_cbar = self.cax = None
else:
# Initialize the colorbar axes in the gridspec so that tight_layout
# works. We will move it where it belongs later. This is a hack.
self.ax_cbar = self._figure.add_subplot(self.gs[0, 0])
self.cax = self.ax_cbar # Backwards compatibility
self.cbar_pos = cbar_pos

self.dendrogram_row = None
self.dendrogram_col = None

def __plot_for_clustergrid__(self, metric, method, colorbar_kws, row_cluster, col_cluster, row_linkage, col_linkage, tree_kws, **kws):
# heatmap square=True sets the aspect ratio on the axes, but that is
# not compatible with the multi-axes layout of clustergrid
if kws.get("square", False):
msg = "``square=True`` ignored in clustermap"
warnings.warn(msg)
kws.pop("square")

colorbar_kws = {} if colorbar_kws is None else colorbar_kws

self.plot_dendrograms(row_cluster, col_cluster, metric, method,
row_linkage=row_linkage, col_linkage=col_linkage,
tree_kws=tree_kws)

try:
xind = self.dendrogram_col.reordered_ind
except AttributeError:
xind = np.arange(self.data2d.shape[1])

try:
yind = self.dendrogram_row.reordered_ind
except AttributeError:
yind = np.arange(self.data2d.shape[0])

self.plot_colors(xind, yind, **kws)
self.plot_matrix(colorbar_kws, xind, yind, **kws)
self._figure.set_size_inches((1,1))
#mpl.rcParams["figure.subplot.hspace"] = hspace
#mpl.rcParams["figure.subplot.wspace"] = wspace
return self
Loading

0 comments on commit 0b13f19

Please sign in to comment.