scverse / scanpy

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

TypeError: __init__() got an unexpected keyword argument 'location' #2318

Open stephwon opened 2 years ago

stephwon commented 2 years ago

I was running this code sc.pl.umap(adata, color = ['KIR3DL1'], frameon = False, layer = 'scvi_normalized') to create umap but it gave me an error message with empty heatmap color bar legend.

스크린샷 2022-09-02 오전 9 34 00

스크린샷 2022-09-01 오후 6 58 54

brykko commented 2 years ago

I just encountered the same issue, using scanpy 1.9.1 and matplotlib 3.5.3. I think it's a recent update to matbplotlib which broke something here. When I rolled back matplotlib to 3.5.2, it ran fine.

stephwon commented 2 years ago

I tried matplotlib 3.5.2 but didn't work but 3.1.3 does but doesn't put out multiple plot in one go

markddesimone commented 1 year ago

Hi Any suggestions on this? I am getting the same issue scanpy 1.9.2 (or 1.9.1):

Thanks

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 sc.pl.umap(adata,color=['EPCAM', 'CD79A', 'CD3D', 'NKG7', 'VFW', 'ACTB', 'ACTA2', 'TPSAB1', 'CD68'], size=12)

File ~/miniconda3/envs/scvi10j/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:669, in umap(adata, **kwargs)
    610 @_wraps_plot_scatter
    611 @_doc_params(
    612     adata_color_etc=doc_adata_color_etc,
   (...)
    616 )
    617 def umap(adata, **kwargs) -> Union[Axes, List[Axes], None]:
    618     """\
    619     Scatter plot in UMAP basis.
    620 
   (...)
    667     tl.umap
    668     """
--> 669     return embedding(adata, 'umap', **kwargs)

File ~/miniconda3/envs/scvi10j/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:452, 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)
    438         _add_categorical_legend(
    439             ax,
    440             color_source_vector,
   (...)
    449             multi_panel=bool(grid),
    450         )
    451     elif colorbar_loc is not None:
--> 452         pl.colorbar(
    453             cax, ax=ax, pad=0.01, fraction=0.08, aspect=30, location=colorbar_loc
    454         )
    456 if return_fig is True:
    457     return fig

File ~/miniconda3/envs/scvi10j/lib/python3.8/site-packages/matplotlib/pyplot.py:2194, in colorbar(mappable, cax, ax, **kw)
   2192 if ax is None:
   2193     ax = gca()
-> 2194 ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)
   2195 return ret

File ~/miniconda3/envs/scvi10j/lib/python3.8/site-packages/matplotlib/figure.py:2343, in Figure.colorbar(self, mappable, cax, ax, use_gridspec, **kw)
   2340 NON_COLORBAR_KEYS = ['fraction', 'pad', 'shrink', 'aspect', 'anchor',
   2341                      'panchor']
   2342 cb_kw = {k: v for k, v in kw.items() if k not in NON_COLORBAR_KEYS}
-> 2343 cb = cbar.colorbar_factory(cax, mappable, **cb_kw)
   2345 self.sca(current_ax)
   2346 self.stale = True

File ~/miniconda3/envs/scvi10j/lib/python3.8/site-packages/matplotlib/colorbar.py:1731, in colorbar_factory(cax, mappable, **kwargs)
   1729     cb = ColorbarPatch(cax, mappable, **kwargs)
   1730 else:
-> 1731     cb = Colorbar(cax, mappable, **kwargs)
   1733 cid = mappable.callbacksSM.connect('changed', cb.update_normal)
   1734 mappable.colorbar = cb

File ~/miniconda3/envs/scvi10j/lib/python3.8/site-packages/matplotlib/colorbar.py:1225, in Colorbar.__init__(self, ax, mappable, **kwargs)
   1223 if isinstance(mappable, martist.Artist):
   1224     _add_disjoint_kwargs(kwargs, alpha=mappable.get_alpha())
-> 1225 ColorbarBase.__init__(self, ax, **kwargs)

File ~/miniconda3/envs/scvi10j/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py:451, in _make_keyword_only.<locals>.wrapper(*args, **kwargs)
    445 if len(args) > idx:
    446     warn_deprecated(
    447         since, message="Passing the %(name)s %(obj_type)s "
    448         "positionally is deprecated since Matplotlib %(since)s; the "
    449         "parameter will become keyword-only %(removal)s.",
    450         name=name, obj_type=f"parameter of {func.__name__}()")
--> 451 return func(*args, **kwargs)

TypeError: __init__() got an unexpected keyword argument 'location'

I was having this problem with scanpy 1.9.1 and matplotlib 3.3.2 I just updated to 1.9.2 and confirm the issue is unchanged

scanpy==1.9.2 anndata==0.8.0 umap==0.5.2 numpy==1.21.5 scipy==1.8.0 pandas==1.4.1 scikit-learn==0.23.2 statsmodels==0.13.2 python-igraph==0.9.9 louvain==0.7.1 pynndescent==0.5.6
-----
anndata     0.8.0
scanpy      1.9.2
-----
PIL                         9.0.1
absl                        NA
asttokens                   NA
attr                        21.4.0
backcall                    0.2.0
beta_ufunc                  NA
binom_ufunc                 NA
brotli                      NA
certifi                     2022.06.15
cffi                        1.14.5
charset_normalizer          2.0.12
chex                        0.1.5
cloudpickle                 2.2.0
colorama                    0.4.4
contextlib2                 NA
cycler                      0.10.0
cython_runtime              NA
cytoolz                     0.12.0
dask                        2022.11.1
dateutil                    2.8.2
debugpy                     1.5.1
decorator                   5.1.1
defusedxml                  0.7.1
deprecate                   0.3.2
docrep                      0.3.2
entrypoints                 0.4
executing                   0.8.3
flax                        0.6.1
fsspec                      2022.11.0
google                      NA
h5py                        3.6.0
hypergeom_ufunc             NA
idna                        3.3
igraph                      0.9.9
ipykernel                   6.9.2
ipython_genutils            0.2.0
ipywidgets                  7.6.5
jax                         0.3.24
jaxlib                      0.3.24
jedi                        0.18.1
jinja2                      3.0.3
joblib                      1.1.0
kiwisolver                  1.3.2
leidenalg                   0.8.9
llvmlite                    0.38.0
louvain                     0.7.1
markupsafe                  2.1.1
matplotlib                  3.3.2
matplotlib_inline           NA
ml_collections              NA
mpl_toolkits                NA
msgpack                     1.0.4
mudata                      0.2.1
multipledispatch            0.6.0
natsort                     8.1.0
nbinom_ufunc                NA
numba                       0.55.1
numexpr                     2.8.0
numpy                       1.21.5
numpyro                     0.10.1
opt_einsum                  v3.3.0
optax                       0.1.3
packaging                   21.3
pandas                      1.4.1
parso                       0.8.3
pexpect                     4.8.0
pickleshare                 0.7.5
pkg_resources               NA
prompt_toolkit              3.0.27
psutil                      5.9.0
ptyprocess                  0.7.0
pure_eval                   0.2.2
pycparser                   2.21
pydev_ipython               NA
pydevconsole                NA
pydevd                      2.6.0
pydevd_concurrency_analyser NA
pydevd_file_utils           NA
pydevd_plugins              NA
pydevd_tracing              NA
pygments                    2.11.2
pynndescent                 0.5.6
pyparsing                   3.0.7
pyro                        1.8.2
pytorch_lightning           1.7.7
pytz                        2021.3
requests                    2.27.1
rich                        NA
scipy                       1.8.0
scrublet                    NA
scvi                        0.19.0
seaborn                     0.11.2
session_info                1.0.0
setuptools                  60.9.3
setuptools_scm              NA
six                         1.16.0
sklearn                     0.23.2
socks                       1.7.1
sphinxcontrib               NA
stack_data                  0.2.0
statsmodels                 0.13.2
tensorboard                 2.10.1
texttable                   1.6.4
threadpoolctl               3.1.0
tlz                         0.12.0
toolz                       0.12.0
torch                       1.11.0
torchmetrics                0.10.2
torchvision                 0.12.0
tornado                     6.1
tqdm                        4.63.0
traitlets                   5.1.1
tree                        0.1.7
typing_extensions           NA
umap                        0.5.2
urllib3                     1.26.8
wcwidth                     0.2.5
yaml                        6.0
zipp                        NA
zmq                         22.3.0
-----
IPython             8.1.1
jupyter_client      7.1.2
jupyter_core        4.9.2
notebook            6.4.9
-----
Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27) [GCC 9.3.0]
Linux-5.4.0-139-generic-x86_64-with-glibc2.10
-----
Session information updated at 2023-02-26 19:13
markddesimone commented 1 year ago

The easiest workaround for this is to not plot the color bar. scanpy 1.9.0 added this option: e.g.:

sc.pl.umap(adata, color=['CD79A'], colorbar_loc=None)