scverse / spatialdata-plot

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

Unable to set vmin and vmax when plotting raster data #303

Closed LucaMarconato closed 2 days ago

LucaMarconato commented 1 month ago

I am trying to plot some raster data with a different normalization (vmin, vmax) for the cmap. Both approaches I used unfortunately don't work, can you have a look at this please?

from spatialdata.datasets import blobs
import spatialdata_plot
import matplotlib.colors
import matplotlib.pyplot as plt

sdata = blobs()

sdata['single_channel'] = sdata['blobs_image'].sel(c=slice(0, 0))

# original
sdata.pl.render_images('single_channel').pl.show()
plt.show()

# attempt 1, doesn't work
sdata.pl.render_images('single_channel', vmin=0, vmax=0.4).pl.show()
plt.show()

# attempt 2, doesn't work
norm = matplotlib.colors.Normalize(vmin=0, vmax=0.4)
sdata.pl.render_images('single_channel', norm=norm).pl.show()
plt.show()
melonora commented 1 month ago

Your third testcase is incorrect btw, the problem here is that clip by default is False so for the third one the output is correct with how you specified it. We should have clip by default being True. Fix incoming

LucaMarconato commented 1 month ago

Thanks for the PR. I have tried using it but I am still seeing the wrong plot. You can find it here: https://github.com/scverse/spatialdata-notebooks/blob/visium_hd_raster_bins/notebooks/examples/technology_visium_hd.ipynb, before the "red" plot. Could you please have a look at it?