Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Option to Plot Highest Absolute Values on Top in sc.pl.umap #3326

Open
tobias-zehnder opened this issue Oct 25, 2024 · 0 comments

Comments

@tobias-zehnder
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants