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

Showing legend by defaults and allowing richer customizability

Open LucaMarconato opened this issue 6 months ago • 1 comments

From @MeyerBender:

  • legends: in my opinion, it would be great to show legends for the channels by default. Alternatively, one could consider implementing something like pl.render_legend() to give full customizability to the user.

This is an example of plot from spatialproteomics. Notebook here.

Image

and the same plot from spatialdata. Notebook here

Image

LucaMarconato avatar May 13 '25 22:05 LucaMarconato

Example code snippet.

import spatialdata as sd
import spatialdata_plot
import matplotlib.pyplot as plt
import numpy as np

# example data
image = sd.models.Image2DModel.parse(
    np.random.rand(4, 100, 100), transformations=None, dims=("c", "x", "y"), c_coords=["DAPI", "CD4", "CD8", "FOXP3"]
)
sdata = sd.SpatialData(images={"image": image})

fig, ax = plt.subplots(1, 2)

# plotting a single channel
sdata.pl.render_images(channel='DAPI').pl.show(ax=ax[0])

# plotting multiple channels
sdata.pl.render_images(channel=['CD4', 'CD8', 'FOXP3']).pl.show(ax=ax[1])

Currently returns this:

Image

MeyerBender avatar May 14 '25 07:05 MeyerBender