UMAP plot color by groups

Hello,
I was wondering if is possible to color different batches under the same color using pl.umap(). In my case I have the following batch ids: s1_b1 s1_b2, s2_b1 s2_b2, s3_b1 s3_b2, and I would like to color by s1, s2, etc.
I tried this:
s_groups = [“s1_b1 s1_b2”,“s2_b1 s2_b2”,“s3_b1 s3_b2”]
sc.pl.umap(adata, color=“batch”, group=s_groups)
I got this error: AttributeError: ‘PathCollection’ object has no property ‘group’

Im newbie in scanpy, any help would be apreciate.

You can create a column or use an existing one to color your cell groups.
Here is my crude example

hi = adata.obs[[‘Samples’]]

hi[‘Platform’] = hi.Samples.replace([“XHP103”],“HiSeq”)
hi[‘Platform’] = hi.Platform.replace([“XHL108”],“NovaSeq”)

adata.obs[‘Platform’] = hi.Platform

sc.pl.umap(adata, color=[ “Platform”])

Hope it helps.

1 Like

Thanks @dummacc100! I fixed like this :

anndata.obs[‘sample’]= anndata.obs[‘batch’].str.extract(r"(^s\d{1})")
sc.pl.umap(anndata, color=“sample”)

Im using the regex: ^s\d{1} to match the letter “s” followed by a number, and adding this to a new column “sample”.