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

Can't plot different elements in a specific axes when multiple coordinate systems are available

Open LucaMarconato opened this issue 2 years ago • 1 comments

Intro

The bug that I'll describe is a consequence of the current coordinate systems implementation and will disappear when it will be refactored. The bug needs to be fixed upstream, but has a consequence in spaitaldata-plot. Nothing to do now, I report it so that we can check that things work when the transformation refactoring is implemented.

To reproduce one can run the last cell of the densenet example notebook.

Description

The function sdata.filter_by_coordinate_system() returns elements that are present in a coordinate system but it doesn't remove eventual transformations to other coordinate systems. This can't be done with the current design.

A consequence in spatialdata plot is a bug in the following scenario (this is what happens in the densenet notebook):

  1. I want to make a plot with 4 subplots, I'll do passing pl.show(ax=axes[i])
  2. Each subplot will have an image element and a shapes element
  3. I want to plot only the aligned coordinate system. The image is mapped to aligned, the shapes is mapped to aligned and global.

Now, since the global is not removed by sdata.filter_by_coordinate_system() (it can't, otherwise it compromises the original object), this leads to spatialdata-plot try to span extra axes, to fit the elements in global, leading to an error.

Solution

Since I will remove the actual transformations from the spatial elements, by placing them instead in sdata, the new sdata object returned by sdata.filter_by_coordinate_system() can just drop the alignment to global without the need to modify the original objects.

LucaMarconato avatar Oct 28 '23 13:10 LucaMarconato

For context, the bug appears in the last cell of the densenet example from the docs.

LucaMarconato avatar Mar 21 '24 00:03 LucaMarconato