In general, sd.pl.render_labels returns a ValueError if color is set to a categorical variable in the attached anndata.obs table
Using the given cosmx data in the tutorial:
cosmx_sdata.pl.render_labels(elements = "2_labels", outline = True, color = 'Area', cmap = 'magma').pl.show(coordinate_systems=["2"])
gives the expected output: segmentation map colored by size of the area in the 'magma' color map
However, the following:
cosmx_sdata.pl.render_labels(elements = "2_labels", outline = True, color = 'fov_labels').pl.show(coordinate_systems=["2"])
Does not return the expected plot (segmentation map with a single color to represent the fov label). Instead it returns the following:
ValueError Traceback (most recent call last)
Cell In[418], [line 1](vscode-notebook-cell:?execution_count=418&line=1)
----> [1](vscode-notebook-cell:?execution_count=418&line=1) cosmx_sdata.pl.render_labels(color = 'fov_labels').pl.show(coordinate_systems=["2"])
File ~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:937, in PlotAccessor.show(self, coordinate_systems, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, na_in_legend, colorbar, wspace, hspace, ncols, frameon, figsize, dpi, fig, title, share_extent, pad_extent, ax, return_ax, save)
[925](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:925) _maybe_set_colors(
[926](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:926) source=sdata[table],
[927](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:927) target=sdata[table],
[928](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:928) key=params_copy.color,
[929](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:929) palette=params_copy.palette,
[930](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:930) )
[932](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:932) rasterize = (params_copy.scale is None) or (
[933](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:933) isinstance(params_copy.scale, str)
[934](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:934) and params_copy.scale != "full"
[935](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:935) and (dpi is not None or figsize is not None)
[936](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:936) )
--> [937](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:937) _render_labels(
[938](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:938) sdata=sdata,
[939](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:939) render_params=params_copy,
[940](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:940) coordinate_system=cs,
[941](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:941) ax=ax,
[942](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:942) fig_params=fig_params,
[943](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:943) scalebar_params=scalebar_params,
[944](https://file+.vscode-resource.vscode-cdn.net/Users/a.tu/dev_env/Translational_Analysis_Multi-program_mIF/~/miniforge3/envs/spatial/lib/python3.11/site-packages/spatialdata_plot/pl/basic.py:944) legend_params=legend_params,
...
File <stringsource>:663, in View.MemoryView.memoryview_cwrapper()
File <stringsource>:353, in View.MemoryView.memoryview.__cinit__()
ValueError: buffer source array is read-only
identical error is found using other spatialdata objects (public, or custom constructed)
Environment is on m2 macbook pro, on python 3.11
spatialdata is version 0.2.2
xarray is version 2023.12.0
skimage is version 0.24.9
anndata is version 0.10.8
pandas is version 2.2.2
In general,
sd.pl.render_labelsreturns aValueErrorifcoloris set to a categorical variable in the attached anndata.obs tableUsing the given cosmx data in the tutorial:
gives the expected output: segmentation map colored by size of the area in the 'magma' color map
However, the following:
Does not return the expected plot (segmentation map with a single color to represent the fov label). Instead it returns the following:
identical error is found using other spatialdata objects (public, or custom constructed)
Environment is on m2 macbook pro, on python 3.11
spatialdatais version 0.2.2xarrayis version 2023.12.0skimageis version 0.24.9anndatais version 0.10.8pandasis version 2.2.2