Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/release-notes/3764.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{func}`scanpy.pl.dotplot` now supports a `group_cmaps` parameter for custom per-group coloring. {smaller}`R Baber`
305 changes: 228 additions & 77 deletions src/scanpy/plotting/_dotplot.py

Large diffs are not rendered by default.

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/dotplot2/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/dotplot3/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/dotplot_gene_symbols/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 added tests/_images/dotplot_group_cmaps/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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_groupby_index/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_groupby_list_catorder/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_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/dotplot_std_scale_var/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_totals/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/multiple_plots/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/ranked_genes_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.
53 changes: 53 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,3 +1821,56 @@ def test_violin_scale_warning(monkeypatch):
monkeypatch.setattr(sc.pl.StackedViolin, "DEFAULT_SCALE", "count", raising=False)
with pytest.warns(FutureWarning, match="Don’t set DEFAULT_SCALE"):
sc.pl.StackedViolin(adata, adata.var_names[:3], groupby="louvain")


params_dotplot_group_cmaps = [
pytest.param("dotplot_group_cmaps", False, id="default"),
pytest.param("dotplot_group_cmaps_swap_axes", True, id="swap_axes"),
]


@pytest.mark.parametrize(("name", "swap_axes"), params_dotplot_group_cmaps)
def test_dotplot_group_cmaps(image_comparer, name, swap_axes):
"""Check group_cmaps parameter with custom color maps per group."""
save_and_compare_images = partial(image_comparer, ROOT, tol=15)

adata = pbmc68k_reduced()

markers = ["SERPINB1", "IGFBP7", "GNLY", "IFITM1", "IMP3", "UBALD2", "LTB", "CLPP"]

group_cmaps = {
"CD14+ Monocyte": "Greys",
"Dendritic": "Purples",
"CD8+ Cytotoxic T": "Reds",
"CD8+/CD45RA+ Naive Cytotoxic": "Greens",
"CD4+/CD45RA+/CD25- Naive T": "Oranges",
"CD4+/CD25 T Reg": "Blues",
"CD4+/CD45RO+ Memory": "hot",
"CD19+ B": "cool",
"CD56+ NK": "winter",
"CD34+": "copper",
}

sc.pl.dotplot(
adata,
markers,
groupby="bulk_labels",
group_cmaps=group_cmaps,
dendrogram=True,
swap_axes=swap_axes,
show=False,
)
save_and_compare_images(name)


def test_dotplot_group_cmaps_raises_error():
"""Check that a ValueError is raised for missing groups in group_cmaps."""
adata = pbmc68k_reduced()
markers = ["CD79A"]
# Intentionally incomplete dictionary to trigger the error
group_cmaps = {"CD19+ B": "Blues"}

with pytest.raises(ValueError, match="missing from the `group_cmaps` dictionary"):
sc.pl.dotplot(
adata, markers, groupby="bulk_labels", group_cmaps=group_cmaps, show=False
)
Loading