It worked! Thank you so much!
Hi all,
I try to do annotation for single cell using scanpy and got this error that I didn't found on the internet:
Would you please have a suggestion? Code is adapt from https://github.com/bnsreenu/python_for_microscopists/blob/master/326_Cell_type_annotation_for_single_cell_RNA_seq_data%E2%80%8B.ipynb
Thank you so much!
sc.pl.umap(adata)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [34], in <cell line: 1>()
----> 1 sc.pl.umap(adata)
File ~/.local/lib/python3.9/site-packages/scanpy/plotting/_tools/scatterplots.py:668, in umap(adata, **kwargs)
609 @_wraps_plot_scatter
610 @_doc_params(
611 adata_color_etc=doc_adata_color_etc,
(...)
615 )
616 def umap(adata, **kwargs) -> Union[Axes, List[Axes], None]:
617 """\
618 Scatter plot in UMAP basis.
619
(...)
666 tl.umap
667 """
--> 668 return embedding(adata, 'umap', **kwargs)
File ~/.local/lib/python3.9/site-packages/scanpy/plotting/_tools/scatterplots.py:162, in embedding(adata, basis, color, gene_symbols, use_raw, sort_order, edges, edges_width, edges_color, neighbors_key, arrows, arrows_kwds, groups, components, dimensions, layer, projection, scale_factor, color_map, cmap, palette, na_color, na_in_legend, size, frameon, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, colorbar_loc, vmax, vmin, vcenter, norm, add_outline, outline_width, outline_color, ncols, hspace, wspace, title, show, save, ax, return_fig, **kwargs)
160 else:
161 cmap = color_map
--> 162 cmap = copy(colormaps.get_cmap(cmap))
163 cmap.set_bad(na_color)
164 kwargs["cmap"] = cmap
AttributeError: 'ColormapRegistry' object has no attribute 'get_cmap'
1 answer
Hi,
I had the same issue, and I resolved it as follows:
I replaced the problematic line in the
~/.local/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.pyfile (line 162) with the following code:cmap = copy(plt.cm.get_cmap(cmap))Since 'plt' was not loaded in the file, I added the following import statement at the top of the same file to import Matplotlib as 'plt':
import matplotlib.pyplot as pltAfter making these changes, I saved the file.
To apply the fix, I restarted my Jupyter Notebook or the Python environment where I was using Scanpy.
After following these steps, the issue was resolved, and my process executed correctly.
Thank you for these steps!
Log in to answer this question.
You probably need to do following again.
If it does not work, you may need to install whole conda. See below-
https://discourse.scverse.org/t/error-when-draw-umap-object-has-no-attribute-get-cmap/1726/3
Seem this installation precess takes a long time. Still waiting. Thank you so much!
Switch to mamba. It's orders of magnitude faster.