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

Unable to set vmin and vmax when plotting raster data

Open LucaMarconato opened this issue 1 year ago • 2 comments

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()

LucaMarconato avatar Jul 14 '24 16:07 LucaMarconato

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

melonora avatar Jul 15 '24 12:07 melonora

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?

LucaMarconato avatar Jul 18 '24 19:07 LucaMarconato

I confirm that it is resolved, thanks @timtreis. I am updating the Visium HD notebook. The problem was that the data is too sparse and mostly made of 0s and 1s, so the interpolation of imshow() brings the 1 pixels close to 0 values.

I now explain this in the Visium HD notebook and plot a subset of the data.

LucaMarconato avatar Sep 08 '24 22:09 LucaMarconato