Feature Request: Option to Plot Highest Absolute Values on Top in sc.pl.umap
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
Description
Currently, sc.pl.umap provides an option to plot cells with higher values on top using an internal sorting step (np.argsort). However, for some use cases, it’s desirable to plot cells with the highest absolute values on top to highlight both large positive and large negative values in continuous color mappings.
Proposed Solution
Add a new option, such as sort_order='abs', to plot the highest absolute values on top, while preserving the original behavior as the default.
Example
Here’s how the option could be used in practice:
sc.pl.umap(adata, color='example_feature', cmap='coolwarm', sort_order='abs')
With this feature, cells with the largest magnitudes (either positive or negative) would be displayed on top, making them more visually prominent when using diverging color maps.
Suggested Implementation
scanpy/source/scanpy/plotting/_tools/scatterplots.py - line 293-295
Instead of
if sort_order and value_to_plot is not None and color_type == "cont":
# Higher values plotted on top, null values on bottom
order = np.argsort(-color_vector, kind="stable")[::-1]
I suggest
if sort_order and value_to_plot is not None and color_type == "cont":
if sort_order == "abs":
order = np.argsort(-np.abs(color_vector), kind="stable")[::-1]
else:
order = np.argsort(-color_vector, kind="stable")[::-1]
Thank you.
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
Start with sc.pl.umap and the sorting logic in src/scanpy/plotting/_tools/scatterplots.py around lines 293-295. Check how sort_order is handled for continuous color values; the work is done when an abs option plots the largest positive or negative magnitudes on top while the existing default behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100