Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pertpy/tools/_coda/_base_coda.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ def plot_boxplots( # pragma: no cover # noqa: D417
level_order: list[str] = None,
figsize: tuple[float, float] | None = None,
dpi: int | None = 100,
layout: Literal["long", "wide"] = "long",
return_fig: bool = False,
) -> Figure | None:
"""Grouped boxplot visualization.
Expand All @@ -1531,10 +1532,13 @@ def plot_boxplots( # pragma: no cover # noqa: D417
args_boxplot: Arguments passed to sns.boxplot.
args_swarmplot: Arguments passed to sns.swarmplot.
figsize: Figure size.
dpi: Dpi setting.
dpi: DPI setting.
palette: The seaborn color map (name) for the barplot.
show_legend: If True, adds a legend.
level_order: Custom ordering of bars on the x-axis.
layout: Controls subplot layout when `plot_facets=True`.
"long": uses floor(sqrt(K)) resulting in taller layout.
"wide": uses ceil(sqrt(K)) resulting in wider layout.
{common_plot_args}

Returns:
Expand All @@ -1559,6 +1563,8 @@ def plot_boxplots( # pragma: no cover # noqa: D417
data = data[modality_key]
if isinstance(palette, Colormap):
palette = list(palette(range(len(data.obs[feature_name].unique()))))
if layout not in {"long", "wide"}:
raise ValueError("layout must be either 'long' or 'wide'")

# y scale transformations
if y_scale == "relative":
Expand Down Expand Up @@ -1608,6 +1614,8 @@ def plot_boxplots( # pragma: no cover # noqa: D417

K = X.shape[1]

col_wrap = int(np.ceil(np.sqrt(K))) if layout == "wide" else int(np.floor(np.sqrt(K)))

if figsize is not None:
height = figsize[0]
aspect = np.round(figsize[1] / figsize[0], 2)
Expand All @@ -1619,7 +1627,7 @@ def plot_boxplots( # pragma: no cover # noqa: D417
plot_df,
col="Cell type",
sharey=False,
col_wrap=int(np.floor(np.sqrt(K))),
col_wrap=col_wrap,
height=height,
aspect=aspect,
)
Expand Down
Loading