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

Feature: datashader also for images

Open LucaMarconato opened this issue 7 months ago • 1 comments

As shown in this thread here: https://github.com/scverse/spatialdata-notebooks/pull/138, when using imshow() on very sparse matrices, the resulting plot can be misleading (the same problem appears also when plotting data using in napari).

A solution could be to enable a method='datashader' approach also for render_images, so that a 2D histogram is computed and the interpolation artifacts can be better controlled.

LucaMarconato avatar Apr 21 '25 20:04 LucaMarconato

To be more explicit, here is the example from the linked discussion. When a matrix is very sparse, plotting a small figure using imshow() (which is used in render_images()), would show a almost totally black image. Since auto is the default interpolation mode in spatialdata-plot, sometimes the image is really completely black.

In the blue plot, which uses plt.spy(), we instead plot all the non-zero values. A similar type of plot could be obtained using datashader with max as transfer function, therefore I see value in enabling method='datashader' in render_images().

Image

LucaMarconato avatar Apr 21 '25 20:04 LucaMarconato