scverse / scverse/scanpy

Allow both 'on data' legend together with legend on righ-hand side of plot

Open
#3,401 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Area - Plotting 🌺 Area – API
Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

What kind of feature would you like to request?

Additional function parameters / changed functionality / changed defaults?

Please describe your wishes

When plotting with "on data" legends, it's not always easy to see which label belongs to which color in the plot. Including the right-hand legend together with the "on data" labels could be a simple fix to improve readability.

I suggest to change the following lines:

https://github.com/scverse/scanpy/blob/391d87ad50d015d1f937d7d993dad36f24b915a5/src/scanpy/plotting/_tools/scatterplots.py#L1141-L1144

as follows:

    if legend_loc not in {None, "none"}:
        for label in cats:
            ax.scatter([], [], c=palette[label], label=label)
        if legend_loc in {"on data", "right margin"}:

Note: I didn't consider any flexibility in preserving the old behaviour and/or extending the parameters to a new legend location descriptor. Personally I feel that would unnecessarily complicate the setting, but I also understand if defaults shouldn't change.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/scanpy/plotting/_tools/scatterplots.py around lines 1141-1144 and trace how legend_loc controls the plotted legend. The change is complete when using "on data" can also display the legend on the right-hand side without changing the intended behavior of other legend locations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.