scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.89k stars 594 forks source link

pl.embedding sets uns.<field>_colors when palette=None #2311

Open jahilton opened 2 years ago

jahilton commented 2 years ago

From pl.embedding documentation, for palette, it states

If provided, values of adata.uns["{var}_colors"] will be set.

This implies that if not provided, then those values will not be set. However, they are being set - either without specifying palette (default:None), or explicitly passing palette=None Either it's a bug, or the documentation is not clear.

Minimal code sample (that we can copy&paste without having any data)

adata = sc.read_h5ad('my_matrix.h5ad')
adata.uns = {} #confirming *_colors is not set already
sc.pl.embedding(adata, basis='X_umap', palette=None, color=['cell_type'])
adata.uns['cell_type_colors']
['#1f77b4',
 '#ff7f0e',
 '#279e68',
 '#d62728',
 '#aa40fc',
 '#8c564b',
 '#e377c2',
 '#b5bd61',
 '#17becf']
LisaSikkema commented 2 years ago

Thanks for your comment Jason! Don't you think the sentence before the one you quoted: "If None, mpl.rcParams["axes.prop_cycle"] is used unless the categorical variable already has colors stored in adata.uns["{var}_colors"]." in combination with the default being "None" would make this clear?

jahilton commented 2 years ago

Hey Lisa! I think I can see that connection now. But I had initially interpreted the "If provided" to mean if I specified, but seems like it also applies to the case where mpl.rcParams["axes.prop_cycle"] is provided for me. Instead of "If provided, values of adata.uns["{var}_colors"] will be set." I would find it more clear to say something like "adata.uns["{var}_colors"] will be set if not already stored"