harpy.pl.plot_sdata#
- harpy.pl.plot_sdata(sdata, image_name, channel=None, labels_name=None, table_name=None, color=None, crd=None, to_coordinate_system='global', render_images_kwargs=mappingproxy({}), render_labels_kwargs=mappingproxy({}), show_kwargs=mappingproxy({}), ax=None)#
Light wrapper around
spatialdata-plotto plot aSpatialDataobject.- Parameters:
sdata (
SpatialData) –SpatialDataobject.image_name (
str) – Image element to plot fromsdata.images.channel (
str|list[str] |None(default:None)) – Channel(s) to visualize, passed to.pl.render_images().labels_name (
str|None(default:None)) – Labels element to plot fromsdata.labels.table_name (
str|None(default:None)) –anndata.AnnDatatable fromsdata.tablesused to color instances of thelabels_name. If specified, the labels element atlabels_nameshould be annotated bytable_name. Ignored ifcolorisNone.color (
str|None(default:None)) – Column fromsdata[table_name].obsor name fromsdata[table_name].var_namesto color the instances fromlabels_name. A ValueError is raised whencoloris specified andtable_nameisNone. Set toNoneif you do not want to color the labels, and only want to visualise the labels inlabels_name.crd (
tuple[int,int,int,int] |None(default:None)) – The coordinates for the region of interest in the format(xmin, xmax, ymin, ymax), in the coordinate systemto_coordinate_system.to_coordinate_system (
str(default:'global')) – Coordinate system to plot.render_images_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments passed to.pl.render_images().render_labels_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments passed to.pl.render_labels(). Ignored iflabels_nameisNone.show_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments passed to.pl.show().ax (
Axes|None(default:None)) –matplotlib.axes.Axesobject to plot on. IfNone, a new axes is created bythe underlying plotting function.
- Return type:
- Returns:
:
matplotlib.axes.Axesobject.- Raises:
ValueError – If
table_nameis not None andlabels_nameis None.ValueError – If
coloris not None andtable_nameis None.ValueError – If
coordinate_systems`in `show_kwargs. Please pass coordinate system to plot viato_coordinate_system.
Examples
>>> from spatialdata.datasets import blobs >>> import matplotlib.pyplot as plt >>> from matplotlib.colors import Normalize >>> import harpy as hp >>> >>> # Load example spatial dataset >>> sdata = blobs() >>> >>> # Configure rendering options >>> render_images_kwargs = { ... "palette": ["red", "blue", "green"], ... "scale": "scale2", ... } >>> render_labels_kwargs = { ... "scale": "scale2", ... "fill_alpha": 0.8, ... "outline_alpha": 0.3, ... } >>> show_kwargs = { ... "title": "my_multichannel_figure", ... "colorbar": False, ... "dpi": 200, ... "figsize": (20, 20), ... } >>> >>> fig, ax = plt.subplots(1, 2) >>> >>> # Plot multichannel image with labels and table annotations >>> hp.pl.plot_sdata( ... sdata, ... image_name="blobs_multiscale_image", ... channel=[0, 1, 2], ... labels_name="blobs_labels", ... table_name="table", ... color="channel_1_sum", ... render_images_kwargs=render_images_kwargs, ... render_labels_kwargs=render_labels_kwargs, ... show_kwargs=show_kwargs, ... ax=ax[0], ... ) >>> >>> # Plot a single channel with intensity normalization and crop >>> norm = Normalize(vmin=0.1, vmax=0.2, clip=True) >>> render_images_kwargs = { ... "cmap": "grey", ... "scale": "full", ... "norm": norm, ... } >>> show_kwargs = { ... "title": "my_channel_1", ... "colorbar": False, ... "dpi": 200, ... "figsize": (20, 20), ... } >>> >>> hp.pl.plot_sdata( ... sdata, ... image_name="blobs_multiscale_image", ... channel=1, ... crd=[100, 300, 100, 300], ... render_images_kwargs=render_images_kwargs, ... render_labels_kwargs=render_labels_kwargs, ... show_kwargs=show_kwargs, ... ax=ax[1], ... )