sc.pl.paga raises TypeError when cax is passed with multiple colors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
Bug report
sc.pl.paga documents cax as "A matplotlib axes object for a potential colorbar" and types it as cax: Axes | None. But when plotting multiple colors, the code indexes it like a sequence (cax[icolor]), which raises TypeError: 'Axes' object is not subscriptable.
Reproduce
import numpy as np, pandas as pd, scipy.sparse as sp
import anndata as ad, scanpy as sc
rng = np.random.default_rng(0)
adata = sc.AnnData(rng.random((60, 20)))
adata.obs['group'] = pd.Categorical(rng.choice(list('abcde'), 60))
k = 5
rows = np.array([0,1,1,2,2,3,3,4,4,0]); cols = np.array([1,0,2,1,3,2,4,3,0,4])
conn = sp.csr_matrix((np.ones(len(rows)),(rows,cols)), shape=(k,k))
adata.uns['paga'] = {'groups':'group','connectivities':conn,'connectivities_tree':conn.copy()}
pos = rng.random((k,2))
fig, ax = plt.subplots()
sc.pl.paga(adata, color=adata.var_names[:2].tolist(), cax=ax, pos=pos, show=False)
Actual
TypeError: 'Axes' object is not subscriptable
Expected
Either accept a single cax (placing the colorbar in it) or a sequence of axes, and document/type accordingly.
Location
src/scanpy/plotting/legacy/_tools/paga.py — cax[icolor] in the colorbar branch.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied reproduction first, then inspect src/scanpy/plotting/legacy/_tools/paga.py around the colorbar branch and its cax handling. Add regression coverage for multiple colors with a single Axes, and ensure the documented and typed behavior supports either one axis or a sequence without raising the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100