Skip to content

Commit 508f857

Browse files
authored
Support colorbar_loc in sc.pl.scatter (#3894)
1 parent 10fe134 commit 508f857

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

docs/release-notes/3894.docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove a few falsely advertised parameters from {func}`scanpy.pl.scatter` {smaller}`P Angerer`

src/scanpy/plotting/_anndata.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -426,24 +426,27 @@ def _scatter_obs( # noqa: PLR0912, PLR0913, PLR0915
426426
key.replace("_", " ") if not is_color_like(key) else "" for key in keys
427427
]
428428

429-
axs: list[Axes] = scatter_base(
430-
xy,
431-
title=title,
432-
alpha=alpha,
433-
component_name=component_name,
434-
axis_labels=axis_labels,
435-
component_indexnames=components + 1,
436-
projection=projection,
437-
colors=color_ids,
438-
highlights=highlights,
439-
colorbars=colorbars,
440-
right_margin=right_margin,
441-
left_margin=left_margin,
442-
sizes=[size for _ in keys],
443-
markers=marker,
444-
color_map=color_map,
445-
show_ticks=show_ticks,
446-
ax=ax,
429+
axs = cast(
430+
"list[Axes]",
431+
scatter_base(
432+
xy,
433+
title=title,
434+
alpha=alpha,
435+
component_name=component_name,
436+
axis_labels=axis_labels,
437+
component_indexnames=components + 1,
438+
projection=projection,
439+
colors=color_ids,
440+
highlights=highlights,
441+
colorbars=colorbars,
442+
right_margin=right_margin,
443+
left_margin=left_margin,
444+
sizes=[size for _ in keys],
445+
markers=marker,
446+
color_map=color_map,
447+
show_ticks=show_ticks,
448+
ax=ax,
449+
),
447450
)
448451

449452
def add_centroid(centroids, name, xy, mask) -> None:

src/scanpy/plotting/_docs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,11 @@
9090
legend_fontoutline
9191
Line width of the legend font outline in pt. Draws a white outline using
9292
the path effect :class:`~matplotlib.patheffects.withStroke`.
93-
colorbar_loc
94-
Where to place the colorbar for continous variables. If `None`, no colorbar
95-
is added.
9693
size
9794
Point size. If `None`, is automatically computed as 120000 / n_cells.
9895
Can be a sequence containing the size for each cell. The order should be
9996
the same as in adata.obs.
10097
{doc_cm_palette}
101-
na_color
102-
Color to use for null or masked values. Can be anything matplotlib accepts as a
103-
color. Used for all points if `color=None`.
104-
na_in_legend
105-
If there are missing values, whether they get an entry in the legend. Currently
106-
only implemented for categorical legends.
10798
frameon
10899
Draw a frame around the scatter plot. Defaults to value set in
109100
:func:`~scanpy.set_figure_params`, defaults to `True`.
@@ -172,6 +163,15 @@
172163
# Docs for pl.pca, pl.tsne, … (everything in _tools.scatterplots)
173164
doc_scatter_embedding = f"""\
174165
{doc_scatter_basic}
166+
colorbar_loc
167+
Where to place the colorbar for continous variables. If `None`, no colorbar
168+
is added.
169+
na_color
170+
Color to use for null or masked values. Can be anything matplotlib accepts as a
171+
color. Used for all points if `color=None`.
172+
na_in_legend
173+
If there are missing values, whether they get an entry in the legend. Currently
174+
only implemented for categorical legends.
175175
{doc_vbound_percentile}
176176
{doc_outline}
177177
{doc_panels}

src/scanpy/plotting/_tools/scatterplots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def embedding( # noqa: PLR0912, PLR0913, PLR0915
100100
legend_fontweight: int | _FontWeight = "bold",
101101
legend_loc: _LegendLoc | None = "right margin",
102102
legend_fontoutline: int | None = None,
103-
colorbar_loc: str | None = "right",
103+
colorbar_loc: Literal["right", "left", "top", "bottom"] | None = "right",
104104
vmax: VBound | Sequence[VBound] | None = None,
105105
vmin: VBound | Sequence[VBound] | None = None,
106106
vcenter: VBound | Sequence[VBound] | None = None,

src/scanpy/plotting/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ def circles(
952952
--------
953953
a = np.arange(11)
954954
circles(a, a, s=a*0.2, c=a, alpha=0.5, ec='none')
955-
pl.colorbar()
955+
plt.colorbar()
956956
License
957957
--------
958958
This code is under [The BSD 3-Clause License]

0 commit comments

Comments
 (0)