How to reuse cmap for other plots?

I have used scanpy to create UMAP figures through this line of code:, color = [‘cell_type’], frameon = False, legend_loc = “right margin”)

However, I am trying to create a stacked bar chart showing prpoportions, using this:
tmp = pd.crosstab(adata.obs[‘cell_type’],adata.obs[‘Sample’], normalize=‘columns’).T.plot(kind=‘bar’, stacked=True)
tmp.legend(title=‘leiden’, bbox_to_anchor=(1.26, 1.02),loc=‘upper right’)

I would like to preserve the same colors used in the UMAP figure to the stacked bar. What should I provide in the cmap parameter to do this (currently it is resuing colors)?

Also, when trying to change the colormap of UMAP plot, I get the error TypeError: functools.partial(<bound method Axes.scatter of <Axes: title={‘center’: ‘cell_type’}>>, s=25.06265664160401, plotnonfinite=True) got multiple values for keyword argument ‘c’
when providing a parameter for c, and nothing changes when providing a parameter for cmap.

You can get the colors used in embedding plots in adata.uns[f'{color_obs}_colors'], which correspond to categories in adata.obs['color_obs'].


adata = sc.datasets.pbmc3k_processed(), color='louvain')
palette_dict = dict(zip(adata.obs['louvain'].cat.categories, adata.uns['louvain_colors']))

Wrt your second question, in embedding plots cmap controls the color scale for continuous covariates, the parameter to change the colors for categorical covariates is palette (see docs for expected inputs)

Thank you, that helps a lot! However, when I supply a parameter to UMAP, the color does not change, and it gives out a warning.
UserWarning: No data for colormapping provided via ‘c’. Parameters ‘cmap’ will be ignored