Skip to content

Mislocation of colorbar legend by sc.pl.scatter #3963

@Fantasque68

Description

@Fantasque68

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

When plotting in given ax, for continuous variable, sc.pl.scatter seems mislocated the colorbar by default settings. It did not stick to the ax it should be, and covered another ax by its side. Just like follow,
Image

Interestingly, sc.pl.embedding returns a correct figure.

Image

I noticed there was an issue about sc.pl.scatter colorbar legend (#1821). I also tried to remove mislocated colorbar by using legend_loc = "none" param. But it did not changed anything.

Minimal code sample

# /// script
# requires-python = ">=3.12"
# dependencies = [
#   "scanpy@git+https://github.com/scverse/scanpy.git@main",
# ]
# ///
#
# This script automatically imports the development branch of scanpy to check for issues

import scanpy as sc
import scFates as scf

## ====Making mislocated colorbar====
fig, axs = plt.subplots(1,2,figsize=(10,4))
fig.subplots_adjust(wspace = 0.3)
sc.pl.scatter(caf_hvg, basis="diffmap",color_map="RdYlBu_r", 
               color="t", 
               ax=axs[0], show=False,
               # legend_loc = "none", # Adding this param neither changed colorbar location nor removed colorbar
               )
scf.pl.trajectory(..., 
                  ax=axs[1])

## ====Correctly located colorbar====
fig, axs = plt.subplots(1,2,figsize=(10,4))
fig.subplots_adjust(wspace = 0.3)
sc.pl.embedding(caf_hvg, basis="diffmap", dimensions=[1,2],color_map="RdYlBu_r", 
              color="t",
              ax=axs[0], show=False)
scf.pl.trajectory(..., 
                  ax=axs[1])

Error output

Versions

Details
Package | Version
-- | --
matplotlib | 3.10.8
pandas | 2.3.3
numpy | 2.3.5
scanpy | 1.12
seaborn | 0.13.2
scFates | 1.2.1
palantir | 1.4.3
anndata | 0.12.8

Python | 3.13.0 \| packaged by Anaconda, Inc. \| (main, Oct 7 2024, 21:29:38) [GCC 11.2.0]
OS | Linux-6.11.0-21-generic-x86_64-with-glibc2.39
CPU | 28 logical CPU cores, x86_64
GPU | ID: 0, Quadro K2000, Driver: 470.256.02, Memory: 1996 MiB
Updated | 2026-01-30 03:34

Dependency | Version
-- | --
scikit-learn | 1.8.0
python-dateutil | 2.9.0.post0
six | 1.17.0
cffi | 2.0.0
executing | 2.2.1
psutil | 7.2.2
wcwidth | 0.5.0
packaging | 25.0
jupyter_core | 5.9.1
elpigraph-python | 0.3.2
plotly | 6.5.2
texttable | 1.7.0
parso | 0.8.5
pycparser | 3.0 (3.00)
donfig | 0.8.1.post1
asttokens | 3.0.1
networkx | 3.6.1
prompt_toolkit | 3.0.52
joblib | 1.5.3
numba | 0.63.1
ipywidgets | 8.1.8
rpy2-rinterface | 3.6.3
threadpoolctl | 3.6.0
pyparsing | 3.3.2
pytz | 2025.2
traitlets | 5.14.3
zarr | 3.1.5
stack-data | 0.6.3
patsy | 1.0.2
tqdm | 4.67.1
jupyter_client | 8.8.0
session-info2 | 0.3
scipy | 1.17.0
statsmodels | 0.14.6
natsort | 8.4.0
legacy-api-wrap | 1.5
Jinja2 | 3.1.6
cycler | 0.12.1
kiwisolver | 1.4.9
llvmlite | 0.46.0
scikit-misc | 0.5.2
platformdirs | 4.5.1
h5py | 3.15.1
tornado | 6.5.4
typing_extensions | 4.15.0
comm | 0.2.3
pillow | 12.1.0
adjustText | 1.3.0
ipython | 9.9.0
pure_eval | 0.2.3
rpy2-robjects | 3.6.3
igraph | 1.0.0
pyzmq | 27.1.0
simpleppt | 1.1.4
decorator | 5.2.1
google-crc32c | 1.8.0
tzlocal | 5.3.1
debugpy | 1.8.19
shapely | 2.1.2
MarkupSafe | 3.0.3
setuptools | 80.10.1
numcodecs | 0.16.5
matplotlib-inline | 0.2.1
PyYAML | 6.0.3
jedi | 0.19.2
ipykernel | 7.1.0
Pygments | 2.19.2
fast-array-utils | 1.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Triage 🩺This issue needs to be triaged by a maintainer

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions