diff --git a/pertpy/plot/_coda.py b/pertpy/plot/_coda.py index 482dc98b..311ee161 100644 --- a/pertpy/plot/_coda.py +++ b/pertpy/plot/_coda.py @@ -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, ) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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, ) diff --git a/pertpy/tools/_coda/_base_coda.py b/pertpy/tools/_coda/_base_coda.py index adae3a5e..2a8e8965 100644 --- a/pertpy/tools/_coda/_base_coda.py +++ b/pertpy/tools/_coda/_base_coda.py @@ -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. @@ -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: @@ -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, @@ -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"). @@ -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. @@ -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: @@ -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 @@ -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: @@ -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. @@ -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) @@ -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, ) @@ -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"]) @@ -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: @@ -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. @@ -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, ) @@ -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, )