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

Can't plot table annotations on points

Open LucaMarconato opened this issue 1 year ago • 6 comments

It seems not to be possible to plot table annotations on points. This was not possible before the table refactoring because tables could not annotate points. @melonora is this expected to work now? If yes, I can make a reproducible example.

LucaMarconato avatar Apr 01 '24 14:04 LucaMarconato

Please do

melonora avatar Apr 01 '24 15:04 melonora

Please check the tests regarding rendering points, in particular related to the categorical as this does plot from tables that annotate points. This is purely in obs though. Are you trying to plot from var and or purely numerical?

melonora avatar Apr 01 '24 20:04 melonora

Thanks for the update. I was trying to plot a var yes. I didn't try categorical.

LucaMarconato avatar Apr 02 '24 01:04 LucaMarconato

Practically, plotting Visium HD data as points may be more efficient than plotting it as shapes, I will explore that.

LucaMarconato avatar Apr 02 '24 01:04 LucaMarconato

@LucaMarconato Can you please give me a reproducible example or check whether this issue is still valid?

melonora avatar Jul 16 '24 10:07 melonora

Apologies, I forgot to send a reproducible example before; here it is.

I show how we can plot from obs and var for shapes, but only from obs and not var for points.

##
import pandas as pd
import spatialdata_plot
from spatialdata.datasets import blobs_annotating_element
import matplotlib.pyplot as plt
from anndata import AnnData
import numpy as np

# setting up the shapes data
sdata = blobs_annotating_element('blobs_circles')
sdata['table'].obs['ehi'] = range(5)
adata = AnnData(X=np.random.rand(5, 10), var=pd.DataFrame(index=[f'gene_{i}' for i in range(10)]))
adata.obs = sdata['table'].obs
adata.uns = sdata['table'].uns
sdata['table2'] = adata

# plotting from obs works
plt.figure(figsize=(10, 10), dpi=72)
sdata.pl.render_shapes('blobs_circles', color='ehi').pl.show()
plt.show()

# plotting from var works
plt.figure(figsize=(10, 10), dpi=72)
sdata.pl.render_shapes('blobs_circles', color='gene_0', table_name='table2').pl.show()
plt.show()

# setting up the points data
sdata = blobs_annotating_element('blobs_points')
sdata['table'].obs['ehi'] = range(200)
adata = AnnData(X=np.random.rand(200, 10), var=pd.DataFrame(index=[f'gene_{i}' for i in range(10)]))
adata.obs = sdata['table'].obs
adata.uns = sdata['table'].uns
sdata['table2'] = adata

# plotting from obs works
plt.figure(figsize=(10, 10), dpi=72)
sdata.pl.render_points('blobs_points', color='ehi').pl.show()
plt.show()

# BUG! plotting from var doesn't
plt.figure(figsize=(10, 10), dpi=72)
sdata.pl.render_points('blobs_points', color='gene_0', table_name='table2').pl.show()
plt.show()

LucaMarconato avatar Jul 18 '24 20:07 LucaMarconato