-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot set custom colors for categorical variables #324
Comments
Hi, can you please try this code here: #242 (comment)? |
There was a typo in the code I linked, please try this one on the latest napari-spatialdata from spatialdata.datasets import blobs_annotating_element
from napari_spatialdata import Interactive
import spatialdata as sd
sdata = blobs_annotating_element("blobs_labels")
##
labels = sdata["blobs_labels"]
print(sd.get_element_instances(labels))
obs = sdata["table"].obs
obs["strings"] = ["A", "A", "B", "B", "C"]
##
sdata["table"].uns["strings_colors"] = {
"A": "#FF5733", # red
"B": "#3498DB", # blue
"C": "#2ECC71", # green
}
Interactive(sdata) If you can't reproduce the bug with the code above please modify the code so that I can reproduce your bug with a small script. Thanks a lot! |
Thank you for sending the details. It's a bit strange because yesterday another user tried the code and it seems that things worked: https://scverse.zulipchat.com/#narrow/stream/315824-spatial/topic/napari-spatialdata/near/476109235. I will look into this; meanwhile please send any other details that could help reproduce the bug. |
It seems these bugs somewhat depend on the operating system. For example, I just tried on my windows laptop to visualize some custom annotations that were not included in the metadata csv file. I manually inserted them in the adata inside the spatialdata object as additional entries of the obs slot. This operation worked perfectly on linux, but on my windows it does not work, for some reason all cells are uniformly colored with a dull gray color, regardless of the annotation I select on the right. Even the annotations taken from the metadata csv are not colored. The same happened some time ago to my student on his windows machine, that's why I suspect these bugs might be different for each OS. |
Please check the napari versions. We have introduced bugfixes in rendering colormaps. So using the old napari version may impact different visible colors |
I confirm I am using the latest napari (0.5.4) on both windows and ubuntu. |
Hi! |
Hi!
I am testing napari-spatialdata on a public Nanostring Cosmx dataset (https://kero.hgc.jp/Breast_Cancer_Spatial.html), and I would like to set a custom color for each label of a specific categorical variable, i.e., the cell types obtained with an external tool. I tried to manually insert a dictionary in the uns slot of the anndata object used as 'table' in the spatialdata object, in the format {<label_name1>:<hex_code1>, <label_name2>:<hex_code2>, ..... }. However, after I load the spatialdata object on napari and I select the desired annotation in the 'observations' panel on the right, an error message pops up, and the annotation is not visualized at all. Here is the full error:
I have no clue about this, especially considering that a student of mine previously succeeded in setting custom colors with an older version of napari-spatialdata. Currently I am using the 0.5.4.dev2+gf84b79b version of napari-spatialdata on napari 0.5.4 in python 3.12.3 on an ubuntu machine.
I am still a beginner with python, can anyone give me any advice on how to solve this?
Thank you in advance!
The text was updated successfully, but these errors were encountered: