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

When multiple categories are plotted, only one legend is shown, and colors do not match

Open LucaMarconato opened this issue 1 year ago • 3 comments

Plotting a single categorical variable works great. This code plots two categorical variables together.

Problems:

  • [ ] The legend gets mixed; I would consider adding two legends.
  • [ ] The plot shows 4 different colors, while the legend shows 2. I think the legend is correct and the plot is wrong.
from spatialdata.datasets import blobs
import spatialdata_plot
import matplotlib.pyplot as plt
from numpy.random import default_rng

RNG = default_rng(0)

sdata = blobs()
sdata['table'].obs['cat0'] = RNG.choice(['A', 'B'], size=len(sdata['table']))
sdata['table'].obs['cat0'] = sdata['table'].obs['cat0'].astype('category')
sdata['table'].obs['cat1'] = RNG.choice(['C', 'D'], size=len(sdata['table']))
sdata['table'].obs['cat1'] = sdata['table'].obs['cat1'].astype('category')

(
    sdata
    .pl.render_labels("blobs_labels", color='cat0')
    .pl.render_labels("blobs_labels", color='cat1')
    .pl.show()
)

plt.show()

image

LucaMarconato avatar Sep 27 '24 13:09 LucaMarconato

How does it look like if you create an ax and then push two separate calls onto it?

timtreis avatar Sep 27 '24 14:09 timtreis

The same plot is produced.

LucaMarconato avatar Sep 27 '24 17:09 LucaMarconato

hm, meh. Yeah, the legends/colorbars for two plots on the same axis are lacking

timtreis avatar Sep 30 '24 13:09 timtreis