spatialdata-plot
spatialdata-plot copied to clipboard
Showing legend by defaults and allowing richer customizability
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.
and the same plot from spatialdata. Notebook here
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: