spatialdata-plot icon indicating copy to clipboard operation
spatialdata-plot copied to clipboard

fix #464

Open sophiamaedler opened this issue 6 months ago • 1 comments

Code which previously failed now generates the expected results:

import spatialdata
import spatialdata_plot
sdata = spatialdata.datasets.blobs()

# add some labelling we want to color with a custom defined palette
sdata["table"].obs["labelling"] = (sdata["table"].obs["instance_id"]>10).astype('int').astype('str')
sdata["table"].obs["labelling"] = sdata["table"].obs["labelling"].astype('category')

# with labels it works
sdata.pl.render_labels("blobs_labels", color = "labelling", palette = ["red", "blue"], groups = ["0", "1"]).pl.show()
# transform to shapes and add necessary annotation
sdata["test_labels"] = spatialdata.to_polygons(sdata["blobs_labels"])

adata = sdata["table"].copy()
adata.obs["region"] = "test_labels"
adata.uns["spatialdata_attrs"]["region"] = "test_labels"
sdata["test_annotation"] = spatialdata.models.TableModel.parse(adata)

# with shapes it throws an error
sdata.pl.render_shapes("test_labels", color = "labelling", palette = ["red", "blue"], groups = ["0", "1"]).pl.show()

image

sophiamaedler avatar May 18 '25 20:05 sophiamaedler