Skip to content
2 changes: 2 additions & 0 deletions src/scanpy/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
violin,
)
from ._dotplot import DotPlot, dotplot
from ._easter_egg import dogplot
from ._matrixplot import MatrixPlot, matrixplot
from ._preprocessing import filter_genes_dispersion, highly_variable_genes
from ._qc import highest_expr_genes
Expand Down Expand Up @@ -63,6 +64,7 @@
"correlation_matrix",
"dendrogram",
"diffmap",
"dogplot",
"dotplot",
"dpt_groups_pseudotime",
"dpt_timeseries",
Expand Down
18 changes: 18 additions & 0 deletions src/scanpy/plotting/_easter_egg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np

HERE = Path(__file__).parent


def dogplot(*_, **__) -> None:
"""Shows who's a good boy"""
pic = np.random.randint(1, 4)
pic_path = HERE / "dogplot_images" / f"doggo_{pic}.jpg"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use importlib.resources instead, something like:

with read_binary("scanpy.plotting", "dogplot_images", f"doggo_{pic}.jpg") as f:
    img = plt.imread(f)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Did it, using importlib.resources.files though


img = plt.imread(pic_path)
plt.imshow(img)
plt.axis("off")
Binary file added src/scanpy/plotting/dogplot_images/doggo_1.jpg
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 src/scanpy/plotting/dogplot_images/doggo_2.jpg
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 src/scanpy/plotting/dogplot_images/doggo_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1851,3 +1851,10 @@ 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")


def test_dogplot():
# Test that the dogplot function runs without errors
sc.pl.dogplot()
# Test that parameters are ignored
sc.pl.dogplot("Good boy", woof=False)
Loading