spatialdata-plot
spatialdata-plot copied to clipboard
Can't plot table annotations on points
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.
Please do
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?
Thanks for the update. I was trying to plot a var yes. I didn't try categorical.
Practically, plotting Visium HD data as points may be more efficient than plotting it as shapes, I will explore that.
@LucaMarconato Can you please give me a reproducible example or check whether this issue is still valid?
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()