Skip to content

Public function for accessing category colors #1881

Description

@brianpenghe

I noticed that the order of .uns['leiden_colors'] might have changed.
Previously I had a set of codes to extract color codes from that attribute and save into a dictionary.
May I ask what's the proper way to extract color codes in the current version of Scanpy?

Thanks

Activity

  1. brianpenghe commented on Jun 17, 2021

    @brianpenghe
    Author
  2. ivirshup commented on Jun 18, 2021

    @ivirshup
    Member

    We'd like to add this to scanpy somewhere, probably in the sc.get module. Maybe sc.get.color_palette(adata, obs_key)?

    Ideally, we eventually just store the colors this way, but this will give developers a stable way to get this information before that happens.

    Related discussions: #596, #1392, (and some more I can't seem to find)

  3. added this to the 1.9.0 milestone on Jun 18, 2021
  4. ivirshup commented on Jun 18, 2021

    @ivirshup
    Member

    The additional cases that would need to be handled (and what I believe the current internal solutions are):

    • What if colors haven't been saved to uns yet
      • If it's an view, we just return what the colors would be by default
      • If it's an "actual" we return the colors, but also assign them to the object
    • What if there's a different number of colors and categories
      • We warn and reassign the colors. If it's a view, we don't modify the object, but probably still warn.

    Most of the logic for handling this internally is wrapped in _get_palette: https://github.com/theislab/scanpy/blob/ed364a887db2eb604d0a09cd72325cb5e1f4e27e/scanpy/plotting/_tools/scatterplots.py#L1192-L1204

  5. changed the title [-]Extract color codes from adata object[/-] [+]Public function for accessing category colors[/+] on Jun 18, 2021
  6. modified the milestones: 1.9.0, 1.10.0 on Apr 1, 2022
  7. modified the milestones: 1.10.0, 1.11.0 on Feb 20, 2024
  8. modified the milestones: 1.11.0, 1.12.0 on Dec 20, 2024
  9. modified the milestones: 1.12.0, 1.13.0 on Nov 10, 2025
  10. modified the milestones: 1.13.0, 1.14.0 on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions