Skip to content

Commit 291c36e

Browse files
Marius1311meeseeksmachine
authored andcommitted
Backport PR scverse#4023: fix: avoid cumulative size reordering across multi-color subplots
1 parent 5166e57 commit 291c36e

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/scanpy/plotting/_tools/scatterplots.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ def embedding( # noqa: PLR0912, PLR0913, PLR0915
295295
elif sort_order and color_type == "cat":
296296
# Null points go on bottom
297297
order = np.argsort(~pd.isnull(color_source_vector), kind="stable")
298-
# Set orders
299-
if isinstance(size, np.ndarray):
300-
size = np.array(size)[order]
298+
# Set orders — use a local to avoid cumulative reordering across
299+
# subplots when multiple color keys are given.
300+
_size = np.array(size)[order] if isinstance(size, np.ndarray) else size
301301
color_source_vector = color_source_vector[order]
302302
color_vector = color_vector[order]
303303
coords = basis_values[:, dims][order, :]
@@ -349,10 +349,10 @@ def embedding( # noqa: PLR0912, PLR0913, PLR0915
349349
)
350350
else:
351351
scatter = (
352-
partial(ax.scatter, s=size, plotnonfinite=True)
352+
partial(ax.scatter, s=_size, plotnonfinite=True)
353353
if scale_factor is None
354354
else partial(
355-
circles, s=size, ax=ax, scale_factor=scale_factor
355+
circles, s=_size, ax=ax, scale_factor=scale_factor
356356
) # size in circles is radius
357357
)
358358

@@ -367,7 +367,7 @@ def embedding( # noqa: PLR0912, PLR0913, PLR0915
367367
# with some transparency.
368368

369369
bg_width, gap_width = outline_width
370-
point = np.sqrt(size)
370+
point = np.sqrt(_size)
371371
gap_size = (point + (point * gap_width) * 2) ** 2
372372
bg_size = (np.sqrt(gap_size) + (point * bg_width) * 2) ** 2
373373
# the default black and white colors can be changes using

0 commit comments

Comments
 (0)