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:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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.