-
Notifications
You must be signed in to change notification settings - Fork 16
render_labels color plot no longer working #403
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
Comments
Morning. Adding a minimal code example here to demo based on scverse/napari-spatialdata#324 (comment) I've tried adding a 'strings' .obs column, with the colors as both a list and a dictionary. If I use a dictionary, the colors come through with Incidentally, I thought colors were supposed to be a list of hexcodes? Isn't that what scanpy would expect if pulling the same colors rather than a dictionary?
The error output is
|
Hi, thanks for the minimal example. ![]() This is the full codeYou can add a headerYou can add text within a collapsed section. You can add an image or a code block, too. import spatialdata as sd
import spatialdata_plot
import napari_spatialdata
from spatialdata.datasets import blobs_annotating_element
import matplotlib.pyplot as plt
print(f"spatialdata version: {sd.__version__}")
print(f"spatialdata_plot version: {spatialdata_plot.__version__}")
print(f"napari_spatialdata version: {napari_spatialdata.__version__}")
sdata = blobs_annotating_element("blobs_labels")
# Add new obs id
obs = sdata["table"].obs
obs["strings"] = ["A", "A", "B", "B", "C"]
obs["strings"] = obs["strings"].astype('category')
# Add colors by dictionary
sdata["table"].uns["strings_colors"] = {
"A": "#FF5733", # red
"B": "#3498DB", # blue
"C": "#2ECC71", # green
}
napari_spatialdata.Interactive(sdata)
fig, axs = plt.subplots(ncols=2)
sdata.pl.render_images('blobs_image').pl.show(ax=axs[0])
sdata.pl.render_labels('blobs_labels', color='strings').pl.show(ax=axs[1])
plt.show() @timtreis @Sonja-Stockhaus I think the error message/or check for type should take into account into this. Specifically, if the column is not converted to a categorical column, then the code gets an exception here:
A check on the dtype of the column could be added there, and if it's a string, we could try to convert it to categorical and raise a warning saying that the user should convert to categorical before.
|
I could reproduce the |
Good point, yes the bug in |
Morning,
Trying to make a side-by-side render_image and render_label plot for my sdata object.
My code worked with earlier versions of spatialdata-plot, but since updating to 0.2.8 have found some issues. (e.g. for render_image, needed to switch from specifying vmin and vmax, to doing this via norm = matplit.colors.Normalize()). My render_image code is now working.
For render_labels though, I seem to get a 'KeyError' when I provide a color parameter. The function works fine when not providing a color parameter. Not sure why, the color name does seem to be a column in
sdata.tables['table'].obs
Any pointers?
Am sure this code worked with earlier versions for spatialdata-plot.
Thanks
Code
Error
The text was updated successfully, but these errors were encountered: