Skip to content

Commit

Permalink
Fix stacked_violin’s standard_scale parameter (#3243)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Sep 20, 2024
1 parent bd75839 commit dbabafa
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/3243.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Accept `'group'` instead of `'obs'` for `standard_scale` parameter in {func}`~scanpy.pl.stacked_violin` {smaller}`P Angerer`
6 changes: 5 additions & 1 deletion src/scanpy/plotting/_stacked_violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def __init__(
)

if standard_scale == "obs":
standard_scale = "group"
msg = "`standard_scale='obs'` is deprecated, use `standard_scale='group'` instead"
warnings.warn(msg, FutureWarning)
if standard_scale == "group":
self.obs_tidy = self.obs_tidy.sub(self.obs_tidy.min(1), axis=0)
self.obs_tidy = self.obs_tidy.div(self.obs_tidy.max(1), axis=0).fillna(0)
elif standard_scale == "var":
Expand Down Expand Up @@ -680,7 +684,7 @@ def stacked_violin(
gene_symbols: str | None = None,
var_group_positions: Sequence[tuple[int, int]] | None = None,
var_group_labels: Sequence[str] | None = None,
standard_scale: Literal["var", "obs"] | None = None,
standard_scale: Literal["var", "group"] | None = None,
var_group_rotation: float | None = None,
layer: str | None = None,
stripplot: bool = StackedViolin.DEFAULT_STRIPPLOT,
Expand Down
Binary file modified tests/_images/dotplot/expected.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 tests/_images/dotplot_dict/expected.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 tests/_images/matrixplot/expected.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 tests/_images/matrixplot2/expected.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 tests/_images/matrixplot_std_scale_group/expected.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 tests/_images/stacked_violin/expected.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 tests/_images/stacked_violin_no_cat_obs/expected.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 tests/_images/stacked_violin_std_scale_group/expected.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 tests/_images/stacked_violin_std_scale_var_dict/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def test_clustermap(image_comparer, obs_keys, name):
save_and_compare_images(name)


@pytest.mark.parametrize(
("id", "fn"),
[
params_dotplot_matrixplot_stacked_violin = [
pytest.param(id, fn, id=id)
for id, fn in [
(
"dotplot",
partial(
Expand Down Expand Up @@ -317,10 +317,13 @@ def test_clustermap(image_comparer, obs_keys, name):
figsize=(8, 2.5),
),
),
],
)
]
]


@pytest.mark.parametrize(("id", "fn"), params_dotplot_matrixplot_stacked_violin)
def test_dotplot_matrixplot_stacked_violin(image_comparer, id, fn):
save_and_compare_images = partial(image_comparer, ROOT, tol=15)
save_and_compare_images = partial(image_comparer, ROOT, tol=5)

adata = krumsiek11()
adata.obs["numeric_column"] = adata.X[:, 0]
Expand Down

0 comments on commit dbabafa

Please sign in to comment.