You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could we change colors for groups from being defined by an array of colors to being a dict mapping from the relevant key/ category to the color? I would find this more intuitive, and much easier to modify. Plus tools like seaborn can accept dicts directly as a palette:
I think we should do that in a way that doesn’t tempt the user to use literal colors like you just did.
The color names people think of have a lot of bad properties for colorblind people and contrast.
Maybe if we redefine common color names? When users specify “red” there, they only want some kind of red, not #ff0000. In one of my analyses, there’s predefined clusters which I recolor like this:
It’s in R and what I do is that I give names to a lot of colorbrewer colors:
My main point is that having an implicit mapping between colors and the categories is not that user or developer friendly. It seems to me like it'd be simpler to just have the mapping be explicit. This wouldn't change much from right now, except for cutting down on some boiler plate in a bunch of plotting functions.
That example was just to demonstrate that it could even be simpler to have an explicit mapping, since we don't have to do:
dict(zip(adata.obs[key].cat.categories, adata.uns[key+"_colors"]))
# and instead could just do:adata.uns[key+"_colors"]
I can imagine that we'd have more than the color attributes for each category. Just think of a .groupby followed by a summary statistics. This gives rise to dataframes that are ordered as .cat.categories. The array-way of storing color attributes is inspired by the way that pd.Categorical manages the string attributes of categories.
Also, seaborn accepts this array-way of passing palettes. You can just do palette=adata.uns['..._colors'] in any of the seaborn functions. At least I think I've done that many times already.
I think that the current way of storing colors is ugly and bad.
One improvement would be to have one dict for colors only adata.uns['colors'] = {'cat_var1': [...], 'cat_var2': ...}
or one dict for all attributes of each categorical adata.uns['louvain'] = {'colors': [...], 'annotations': [...], 'mean_expr': [...], 'markers': [...]}
Evidently, in the latter case, one would rather like to have a more powerful pd.Categorical class that can do more than just attach a string label to an integer.
I also agree that making the mapping explicit using dictionaries would be much more intuitive, that is also how Seurat works.
@falexwolf are you proposing declaring all the colors in a single dictionary stored in adata.uns["uns"]? Than those colors would act as defaults and could be overwritten by e.g. using the palette parameter in seaborn.
Activity
flying-sheep commentedon Apr 8, 2019
I think we should do that in a way that doesn’t tempt the user to use literal colors like you just did.
The color names people think of have a lot of bad properties for colorblind people and contrast.
Maybe if we redefine common color names? When users specify “red” there, they only want some kind of red, not
#ff0000. In one of my analyses, there’s predefined clusters which I recolor like this:It’s in R and what I do is that I give names to a lot of colorbrewer colors:
In python that would be:
ivirshup commentedon Apr 8, 2019
My main point is that having an implicit mapping between colors and the categories is not that user or developer friendly. It seems to me like it'd be simpler to just have the mapping be explicit. This wouldn't change much from right now, except for cutting down on some boiler plate in a bunch of plotting functions.
That example was just to demonstrate that it could even be simpler to have an explicit mapping, since we don't have to do:
flying-sheep commentedon Apr 8, 2019
Sure, I agree with you generally. I’m just saying that an easy, userfriendly way should make it easy to get beautiful colors, not ugly ones.
So in the PR tuning that interface to be nicer, we should do something about that.
falexwolf commentedon Apr 26, 2019
Sorry about the late response here...
I can imagine that we'd have more than the color attributes for each category. Just think of a
.groupbyfollowed by a summary statistics. This gives rise to dataframes that are ordered as.cat.categories. The array-way of storing color attributes is inspired by the way thatpd.Categoricalmanages the string attributes of categories.Also, seaborn accepts this array-way of passing palettes. You can just do
palette=adata.uns['..._colors']in any of the seaborn functions. At least I think I've done that many times already.I think that the current way of storing colors is ugly and bad.
One improvement would be to have one dict for colors only
adata.uns['colors'] = {'cat_var1': [...], 'cat_var2': ...}or one dict for all attributes of each categorical
adata.uns['louvain'] = {'colors': [...], 'annotations': [...], 'mean_expr': [...], 'markers': [...]}Evidently, in the latter case, one would rather like to have a more powerful
pd.Categoricalclass that can do more than just attach a string label to an integer.AlbertoFabbri93 commentedon Jul 20, 2026
There is a duplicate issue at #4206.
I also agree that making the mapping explicit using dictionaries would be much more intuitive, that is also how Seurat works.
@falexwolf are you proposing declaring all the colors in a single dictionary stored in
adata.uns["uns"]? Than those colors would act as defaults and could be overwritten by e.g. using thepaletteparameter in seaborn.