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

Bug: plotting after sorting a table

Open LucaMarconato opened this issue 2 years ago • 2 comments

We just caught a bug in napari-spatialdata (described in this comment https://github.com/scverse/napari-spatialdata/pull/175#issuecomment-1793764234, but no need to read there, I will summarize here) and I just noticed that this a bug also of spatialdata-plot.

Currently, napari_spatialdata, when plotting labels, seems to match the table to the labels using the order of the rows instead than using the instance_key (this is handled correctly for circles btw). I verified this for spatialdata-plot and I noticed that the order of the table influences the plot. I am surprised that this happens because I would have bet that the tests added here https://github.com/scverse/spatialdata-plot/pull/163/files would have covered also this case, but apparently this is not the case.

The code to reproduce this (which makes the plots both with napari and spatialdata-plot and then one needs to check by eye) is the one posted in this comment here: https://github.com/scverse/napari-spatialdata/pull/175#issuecomment-1793767601.

Please notice that spatialdata-plot can't make the first two plots because of this bug with plotting continuous annotations to labels: https://github.com/scverse/spatialdata-plot/issues/165.

Also please notice that I had to add

import matplotlib.pyplot as plt
plt.show()

in the end because for some reasons pl.show() was not working. This is something tracked elsewhere, I will report it separately by reopening that issue.

LucaMarconato avatar Nov 05 '23 15:11 LucaMarconato

Anyway, the bug has a simple solution. Calling the function match_table_to_element() https://github.com/scverse/spatialdata-plot/issues/178 returns a table with rows that match the element, even in the case of partial overlap between the instances in the element and the rows of the table.

A better solution is to drop region, region_key, instance_key (but this will take some time). CC @giovp @kevinyamauchi.

LucaMarconato avatar Nov 05 '23 15:11 LucaMarconato

sdata3: image

sdata4: image

LucaMarconato avatar Nov 05 '23 15:11 LucaMarconato