scanpy icon indicating copy to clipboard operation
scanpy copied to clipboard

sc.pl.umap(... legend_loc='upper right') does not work

Open alexlenail opened this issue 2 years ago • 1 comments

From the scanpy docs:

legend_loc : str (default: 'right margin')

Location of legend, either 'on data', 'right margin' or a valid keyword for the loc parameter of Legend.

From the matplotlib Legend docs:

The strings 'upper left', 'upper right', 'lower left', 'lower right' place the legend at the corresponding corner of the axes/figure.

But

sc.pl.umap(adata, color='mouse.id', legend_loc='upper right')

does not work: the legend just disappears. When I go and inspect the legend, I find that ax.legend_._loc is 0

Location String Location Code
'best' 0
'upper right' 1

so it isn't being properly set.

alexlenail avatar Sep 13 '22 16:09 alexlenail

It seems like the relevant function doesn't include a conditional branch for this case: https://github.com/scverse/scanpy/blob/11d0b8e992ad145eeb3f666aa4e006bd204272de/scanpy/plotting/_tools/scatterplots.py#L1069

alexlenail avatar Sep 13 '22 16:09 alexlenail

This is probably addressed in #2267

LisaSikkema avatar Sep 24 '22 17:09 LisaSikkema