question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uns categorical colour maping as a dictionary

See original GitHub issue
  • [ x] Additional function parameters / changed functionality / changed defaults?
  • New analysis tool: A simple analysis tool you have been using and are missing in sc.tools?
  • New plotting function: A kind of plot you would like to seein sc.pl?
  • External tools: Do you know an existing package that should go into sc.external.*?
  • Other?

When determining colours of categorical variables in uns they are based on alphabetical order (if I am not mistaken) - being represented just as an ordered list. Thus it is a bit inconvenient to change colours, especially if categories change during the analysis - the whole order changes and the mapping breaks. Would it be possible to use a dictionary of colours as values and categories as keys (with a default for any categories missing colours)?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ivirshupcommented, Jul 30, 2020

I think we should allow for categorical colors along either axis, and right now it’s becomes ambiguous. A good example of an annotation that can apply to both observations and variables is species.

I’d like to shift to a nested model to limit the amount of reserved keys in .uns. It reduces that chance of unintentional naming collisions.

As for the amount of things that would need to change, a lot has to change anyways. Hardly any code that works with the current setup will work with mappings (len is all I can think of). If we’re already making a breaking change, might as well take advantage and future proof it a bit.

0reactions
fidelramcommented, Aug 17, 2020

I agree with @ivirshup that the best would be to have a single function that returns the colors. This also facilitates documentation. The actual implementation afterwards could be modified without much effort.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uns categorical colour maping as a dictionary #1340 - GitHub
When determining colours of categorical variables in uns they are based on alphabetical order (if I am not mistaken) - being represented just...
Read more >
scanpy.pl.umap — Scanpy 1.9.1 documentation
Colors to use for plotting categorical annotation groups. The palette can be a valid ListedColormap name ( 'Set2' , 'tab20' , …) ...
Read more >
Categorical Feature Encoding in Python | Towards Data Science
A guide for encoding binary, ordinal, and nominal categorical features in Python using sklearn and Pandas.
Read more >
python - .map is not mapping correct color values to a barchart
In order to keep the color consistent, I am using a dictionary which map all the unique values in the column with a...
Read more >
Data handling in scvi-tools
field_registries is dictionary which maps registry keys (e.g. batch , labels ) to ... categorical_mapping is the categorical to integer mapping of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found