diff --git a/src/spatialdata_plot/pl/basic.py b/src/spatialdata_plot/pl/basic.py index e1d28d3b..8b3ce310 100644 --- a/src/spatialdata_plot/pl/basic.py +++ b/src/spatialdata_plot/pl/basic.py @@ -1513,6 +1513,18 @@ def _draw_colorbar( if fig_params.frameon is False: ax.axis("off") + if has_shapes and wants_shapes: + empty_shape_elements = [ + name + for name in wanted_elements + if name in sdata.shapes and not sdata.shapes[name]["geometry"].apply(lambda g: not g.is_empty).any() + ] + if empty_shape_elements: + raise ValueError( + f"Cannot render shape element(s) {empty_shape_elements} in coordinate system {cs!r}: " + "all geometries are empty. Drop the element or restore at least one non-empty geometry." + ) + extent = get_extent( sdata, coordinate_system=cs,