scverse / spatialdata-plot

Static plotting for spatialdata
BSD 3-Clause "New" or "Revised" License
35 stars 14 forks source link

palette argument has no effect on plotting colors in pl.render_shapes() #145

Closed sopvdl closed 1 year ago

sopvdl commented 1 year ago

Hi there, thanks for this great tool! Super useful so far, but I'm running into some issues trying specify colors for categorical values with pl.render_shapes().

Specifying colors with the palette argument, I get my desired colors in the legend but not in the plot itself.

sdata.pl.render_shapes('cell_boundaries', color='graphclust', palette=ListedColormap(['blue', 'red']), groups=['2', '9']).pl.show(ax=ax, title='clusters')

I've tried many things, also without the groups argument but so far haven't been able to use palette to specify colors for categorical values in the plot itself. Would be great to be able to do this because the standard colors can be hard to see :)

LucaMarconato commented 1 year ago

Thanks for the fix @timtreis and @Sonja-Stockhaus!

@sopvdl the issue should be fixed now using the latest main version of spatialdata-plot.

sopvdl commented 1 year ago

Awesome thanks for the fix it's working now!

But I do notice when I'm now plotting with the groups argument, the na_color argument doesn't seem to be working anymore. As in the cells that are not in the groups will not be plotted and specifying a color with na_color has no effect. Are you also seeing this?

timtreis commented 1 year ago

Yes, this is actually the intended behaviour for groups, analog to scanpy or squidpy.

One easy way to achieve your desired output would be to add a new entry in obs in which you store this annotation, for example like this

sdata.table.obs["new_cluster"] = "NA"
sdata.table.obs.loc[sdata.table.obs.array_row==15.0, "new_cluster"] = "celltype_A"
sdata.table.obs.loc[sdata.table.obs.array_row==47.0, "new_cluster"] = "celltype_B"
sdata.table.obs.new_cluster = sdata.table.obs.new_cluster.astype("category")

sdata.pl.render_shapes("ST8059048_shapes", color="new_cluster", palette=["grey", "red", "blue"]).pl.show()
image