scverse / spatialdata-plot

Static plotting for spatialdata
BSD 3-Clause "New" or "Revised" License
27 stars 13 forks source link

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

Open LucaMarconato opened 10 months ago

LucaMarconato commented 10 months ago

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 commented 5 months ago

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