Skip to content

Commit

Permalink
Rename cmap to palette (#553)
Browse files Browse the repository at this point in the history
* Rename cmap to palette

Signed-off-by: zethson <lukas.heumos@posteo.net>

* Rename cmap to palette

Signed-off-by: zethson <lukas.heumos@posteo.net>

* Update pertpy/plot/_coda.py

---------

Signed-off-by: zethson <lukas.heumos@posteo.net>
  • Loading branch information
Zethson authored Mar 11, 2024
1 parent 6d44cc4 commit 27fdd78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
18 changes: 9 additions & 9 deletions pertpy/plot/_coda.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def stacked_barplot( # pragma: no cover
"""
warnings.warn(
"This function is deprecated and will be removed in pertpy 0.8.0!"
" Please use the corresponding 'pt.tl' object",
" Please use the corresponding 'pt.tl' object for plotting function directly.",
FutureWarning,
stacklevel=2,
)
Expand All @@ -128,7 +128,7 @@ def stacked_barplot( # pragma: no cover
modality_key=modality_key,
figsize=figsize,
dpi=dpi,
cmap=cmap,
palette=cmap,
show_legend=show_legend,
level_order=level_order,
)
Expand Down Expand Up @@ -186,7 +186,7 @@ def effects_barplot( # pragma: no cover
"""
warnings.warn(
"This function is deprecated and will be removed in pertpy 0.8.0!"
" Please use the corresponding 'pt.tl' object",
" Please use the corresponding 'pt.tl' object for plotting function directly.",
FutureWarning,
stacklevel=2,
)
Expand All @@ -204,7 +204,7 @@ def effects_barplot( # pragma: no cover
plot_zero_cell_type=plot_zero_cell_type,
figsize=figsize,
dpi=dpi,
cmap=cmap,
palette=cmap,
level_order=level_order,
args_barplot=args_barplot,
)
Expand Down Expand Up @@ -262,7 +262,7 @@ def boxplots( # pragma: no cover
"""
warnings.warn(
"This function is deprecated and will be removed in pertpy 0.8.0!"
" Please use the corresponding 'pt.tl' object",
" Please use the corresponding 'pt.tl' object for plotting function directly.",
FutureWarning,
stacklevel=2,
)
Expand All @@ -282,7 +282,7 @@ def boxplots( # pragma: no cover
args_swarmplot=args_swarmplot,
figsize=figsize,
dpi=dpi,
cmap=cmap,
palette=cmap,
show_legend=show_legend,
level_order=level_order,
)
Expand Down Expand Up @@ -331,7 +331,7 @@ def rel_abundance_dispersion_plot( # pragma: no cover
"""
warnings.warn(
"This function is deprecated and will be removed in pertpy 0.8.0!"
" Please use the corresponding 'pt.tl' object",
" Please use the corresponding 'pt.tl' object for plotting function directly.",
FutureWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -412,7 +412,7 @@ def draw_tree( # pragma: no cover
"""
warnings.warn(
"This function is deprecated and will be removed in pertpy 0.8.0!"
" Please use the corresponding 'pt.tl' object",
" Please use the corresponding 'pt.tl' object for plotting function directly.",
FutureWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -585,7 +585,7 @@ def effects_umap( # pragma: no cover
"""
warnings.warn(
"This function is deprecated and will be removed in pertpy 0.8.0!"
" Please use the corresponding 'pt.tl' object",
" Please use the corresponding 'pt.tl' object for plotting function directly.",
FutureWarning,
stacklevel=2,
)
Expand Down
45 changes: 23 additions & 22 deletions pertpy/tools/_coda/_base_coda.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ def _stackbar( # pragma: no cover
level_names: list[str],
figsize: tuple[float, float] | None = None,
dpi: int | None = 100,
cmap: ListedColormap | None = cm.tab20,
palette: ListedColormap | None = cm.tab20,
show_legend: bool | None = True,
) -> plt.Axes:
"""Plots a stacked barplot for one (discrete) covariate.
Expand All @@ -1141,7 +1141,7 @@ def _stackbar( # pragma: no cover
level_names: Names of the covariate's levels
figsize: Figure size. Defaults to None.
dpi: Dpi setting. Defaults to 100.
cmap: The color map for the barplot. Defaults to cm.tab20.
palette: The color map for the barplot. Defaults to cm.tab20.
show_legend: If True, adds a legend. Defaults to True.
Returns:
Expand All @@ -1164,7 +1164,7 @@ def _stackbar( # pragma: no cover
r,
bars,
bottom=cum_bars,
color=cmap(n % cmap.N),
color=palette(n % palette.N),
width=barwidth,
label=type_names[n],
linewidth=0,
Expand All @@ -1187,9 +1187,10 @@ def plot_stacked_barplot( # pragma: no cover
modality_key: str = "coda",
figsize: tuple[float, float] | None = None,
dpi: int | None = 100,
cmap: ListedColormap | None = cm.tab20,
palette: ListedColormap | None = cm.tab20,
show_legend: bool | None = True,
level_order: list[str] = None,
**kwargs,
) -> plt.Axes:
"""Plots a stacked barplot for all levels of a covariate or all samples (if feature_name=="samples").
Expand All @@ -1199,7 +1200,7 @@ def plot_stacked_barplot( # pragma: no cover
modality_key: If data is a MuData object, specify which modality to use. Defaults to "coda".
figsize: Figure size. Defaults to None.
dpi: Dpi setting. Defaults to 100.
cmap: The matplotlib color map for the barplot. Defaults to cm.tab20.
palette: The matplotlib color map for the barplot. Defaults to cm.tab20.
show_legend: If True, adds a legend. Defaults to True.
level_order: Custom ordering of bars on the x-axis. Defaults to None.
Expand Down Expand Up @@ -1236,7 +1237,7 @@ def plot_stacked_barplot( # pragma: no cover
level_names=data.obs.index,
figsize=figsize,
dpi=dpi,
cmap=cmap,
palette=palette,
show_legend=show_legend,
)
else:
Expand All @@ -1262,7 +1263,7 @@ def plot_stacked_barplot( # pragma: no cover
level_names=levels,
figsize=figsize,
dpi=dpi,
cmap=cmap,
palette=palette,
show_legend=show_legend,
)
return ax
Expand All @@ -1278,7 +1279,7 @@ def plot_effects_barplot( # pragma: no cover
plot_zero_cell_type: bool = False,
figsize: tuple[float, float] | None = None,
dpi: int | None = 100,
cmap: str | ListedColormap | None = cm.tab20,
palette: str | ListedColormap | None = cm.tab20,
level_order: list[str] = None,
args_barplot: dict | None = None,
) -> plt.Axes | sns.axisgrid.FacetGrid | None:
Expand All @@ -1300,7 +1301,7 @@ def plot_effects_barplot( # pragma: no cover
Defaults to False.
figsize: Figure size. Defaults to None.
dpi: Figure size. Defaults to 100.
cmap: The seaborn color map for the barplot. Defaults to cm.tab20.
palette: The seaborn color map for the barplot. Defaults to cm.tab20.
level_order: Custom ordering of bars on the x-axis. Defaults to None.
args_barplot: Arguments passed to sns.barplot. Defaults to None.
Expand Down Expand Up @@ -1380,8 +1381,8 @@ def plot_effects_barplot( # pragma: no cover

# If plot as facets, create a FacetGrid and map barplot to it.
if plot_facets:
if isinstance(cmap, ListedColormap):
cmap = np.array([cmap(i % cmap.N) for i in range(len(plot_df["Cell Type"].unique()))])
if isinstance(palette, ListedColormap):
palette = np.array([palette(i % palette.N) for i in range(len(plot_df["Cell Type"].unique()))])
if figsize is not None:
height = figsize[0]
aspect = np.round(figsize[1] / figsize[0], 2)
Expand All @@ -1402,7 +1403,7 @@ def plot_effects_barplot( # pragma: no cover
sns.barplot,
"Cell Type",
"value",
palette=cmap,
palette=palette,
order=level_order,
**args_barplot,
)
Expand All @@ -1422,25 +1423,25 @@ def plot_effects_barplot( # pragma: no cover
else:
_, ax = plt.subplots(figsize=figsize, dpi=dpi)
if len(covariate_names) == 1:
if isinstance(cmap, ListedColormap):
cmap = np.array([cmap(i % cmap.N) for i in range(len(plot_df["Cell Type"].unique()))])
if isinstance(palette, ListedColormap):
palette = np.array([palette(i % palette.N) for i in range(len(plot_df["Cell Type"].unique()))])
sns.barplot(
data=plot_df,
x="Cell Type",
y="value",
palette=cmap,
palette=palette,
ax=ax,
)
ax.set_title(covariate_names[0])
else:
if isinstance(cmap, ListedColormap):
cmap = np.array([cmap(i % cmap.N) for i in range(len(covariate_names))])
if isinstance(palette, ListedColormap):
palette = np.array([palette(i % palette.N) for i in range(len(covariate_names))])
sns.barplot(
data=plot_df,
x="Cell Type",
y="value",
hue="Covariate",
palette=cmap,
palette=palette,
ax=ax,
)
cell_types = pd.unique(plot_df["Cell Type"])
Expand All @@ -1461,7 +1462,7 @@ def plot_boxplots( # pragma: no cover
args_swarmplot: dict | None = None,
figsize: tuple[float, float] | None = None,
dpi: int | None = 100,
cmap: str | None = "Blues",
palette: str | None = "Blues",
show_legend: bool | None = True,
level_order: list[str] = None,
) -> plt.Axes | sns.axisgrid.FacetGrid | None:
Expand All @@ -1484,7 +1485,7 @@ def plot_boxplots( # pragma: no cover
args_swarmplot: Arguments passed to sns.swarmplot. Defaults to {}.
figsize: Figure size. Defaults to None.
dpi: Dpi setting. Defaults to 100.
cmap: The seaborn color map for the barplot. Defaults to "Blues".
palette: The seaborn color map for the barplot. Defaults to "Blues".
show_legend: If True, adds a legend. Defaults to True.
level_order: Custom ordering of bars on the x-axis. Defaults to None.
Expand Down Expand Up @@ -1578,7 +1579,7 @@ def plot_boxplots( # pragma: no cover
sns.boxplot,
feature_name,
value_name,
palette=cmap,
palette=palette,
order=level_order,
**args_boxplot,
)
Expand Down Expand Up @@ -1623,7 +1624,7 @@ def plot_boxplots( # pragma: no cover
hue=feature_name,
data=plot_df,
fliersize=1,
palette=cmap,
palette=palette,
ax=ax,
**args_boxplot,
)
Expand Down

0 comments on commit 27fdd78

Please sign in to comment.