scverse / scanpy

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

stacked_violin is broken on master #2118

Closed Koncopd closed 2 years ago

Koncopd commented 2 years ago

sc.pl.stacked_violin(adata_pl, var_names=check_terms, groupby='ct_cond', swap_axes=True)

always get the error

TypeError                                 Traceback (most recent call last)
<ipython-input-40-5bc1cab6ebf2> in <module>
----> 1 sc.pl.stacked_violin(adata_pl, var_names=check_terms, groupby='ct_cond', swap_axes=True)

~\Apps\Miniconda3\envs\work38\lib\site-packages\scanpy\plotting\_stacked_violin.py in stacked_violin(adata, var_names, groupby, log, use_raw, num_categories, title, colorbar_title, figsize, dendrogram, gene_symbols, var_group_positions, var_group_labels, standard_scale, var_group_rotation, layer, stripplot, jitter, size, scale, yticklabels, order, swap_axes, show, save, return_fig, row_palette, cmap, ax, vmin, vmax, vcenter, norm, **kwds)
    717         return vp
    718     else:
--> 719         vp.make_figure()
    720         savefig_or_show(StackedViolin.DEFAULT_SAVE_PREFIX, show=show, save=save)
    721         show = settings.autoshow if show is None else show

~\Apps\Miniconda3\envs\work38\lib\site-packages\scanpy\plotting\_baseplot_class.py in make_figure(self)
    738         if self.legends_width > 0:
    739             legend_ax = self.fig.add_subplot(gs[0, 1])
--> 740             self._plot_legend(legend_ax, return_ax_dict, normalize)
    741 
    742         self.ax_dict = return_ax_dict

~\Apps\Miniconda3\envs\work38\lib\site-packages\scanpy\plotting\_baseplot_class.py in _plot_legend(self, legend_ax, return_ax_dict, normalize)
    535         color_legend_ax = fig.add_subplot(legend_gs[1])
    536 
--> 537         self._plot_colorbar(color_legend_ax, normalize)
    538         return_ax_dict['color_legend_ax'] = color_legend_ax
    539 

~\Apps\Miniconda3\envs\work38\lib\site-packages\scanpy\plotting\_baseplot_class.py in _plot_colorbar(self, color_legend_ax, normalize)
    508         import matplotlib.colorbar
    509 
--> 510         matplotlib.colorbar.Colorbar(
    511             color_legend_ax, orientation='horizontal', cmap=cmap, norm=normalize
    512         )

TypeError: __init__() missing 1 required positional argument: 'mappable'
ivirshup commented 2 years ago

Can you give some version info? I can't reproduce with:

In [1]: import scanpy as sc

In [2]: pbmc = sc.datasets.pbmc3k_processed().raw.to_adata()

In [3]: genes = list(pbmc.uns["rank_genes_groups"]["names"][0])

In [4]: sc.pl.stacked_violin(pbmc, var_names=genes, groupby='louvain', swap_axes=True)
Versions ``` ----- scanpy 1.9.0.dev63+gb69015e9 session_info 1.0.0 ----- PIL 9.0.0 anndata 0.8.0rc1 appnope 0.1.2 asciitree NA asttokens NA backcall 0.2.0 beta_ufunc NA binom_ufunc NA cffi 1.15.0 cloudpickle 2.0.0 cycler 0.10.0 cython_runtime NA dask 2021.12.0 dateutil 2.8.2 debugpy 1.5.1 decorator 5.1.0 defusedxml 0.7.1 entrypoints 0.3 executing 0.8.2 fasteners NA fsspec 2022.01.0 google NA h5py 3.6.0 igraph 0.9.9 ipykernel 6.7.0 ipython_genutils 0.2.0 jedi 0.18.1 jinja2 3.0.3 joblib 1.1.0 jupyter_server 1.13.1 kiwisolver 1.3.2 leidenalg 0.8.8 llvmlite 0.38.0 markupsafe 2.0.1 matplotlib 3.5.1 matplotlib_inline NA mpl_toolkits NA msgpack 1.0.3 natsort 8.0.2 nbinom_ufunc NA numba 0.55.0 numcodecs 0.9.1 numexpr 2.7.3 numpy 1.21.5 packaging 21.3 pandas 1.4.0 parso 0.8.2 pexpect 4.8.0 pickleshare 0.7.5 pkg_resources NA prompt_toolkit 3.0.22 psutil 5.8.0 ptyprocess 0.7.0 pure_eval 0.2.1 pyarrow 6.0.1 pydev_ipython NA pydevconsole NA pydevd 2.6.0 pydevd_concurrency_analyser NA pydevd_file_utils NA pydevd_plugins NA pydevd_tracing NA pyexpat NA pygments 2.10.0 pyparsing 3.0.6 pytz 2021.3 ruamel NA scipy 1.7.3 setuptools 60.5.0 setuptools_scm NA sinfo 0.3.4 sitecustomize NA six 1.16.0 sklearn 1.0.2 sparse 0.13.0 sphinxcontrib NA stack_data 0.1.4 tables 3.7.0 tblib 1.7.0 texttable 1.6.4 threadpoolctl 3.0.0 tlz 0.11.2 toolz 0.11.2 tornado 6.1 traitlets 5.1.1 typing_extensions NA wcwidth 0.2.5 yaml 6.0 zappy NA zarr 2.10.3 zmq 22.3.0 ----- IPython 8.0.0 jupyter_client 7.1.0 jupyter_core 4.9.1 jupyterlab 3.2.6 notebook 6.4.7 ----- Python 3.9.9 (main, Nov 21 2021, 03:23:42) [Clang 13.0.0 (clang-1300.0.29.3)] macOS-11.6.2-x86_64-i386-64bit ----- Session information updated at 2022-01-24 16:14 ```
Koncopd commented 2 years ago

Yes, i use matplotlib version 3.3.4. for this version https://matplotlib.org/3.3.4/api/colorbar_api.html?highlight=colorbar#matplotlib.colorbar.Colorbar mappable is required. For the last version it is not the case. https://matplotlib.org/stable/api/colorbar_api.html

ivirshup commented 2 years ago

Here's the commit that caused the issue: https://github.com/theislab/scanpy/commit/4cb8a61df2628f00ce7d1fff5a3b25dcbe2222ff

So the difference was switching from ColorBarBase to ColorBar, but also it looks like ColorBarBase only allows a single positional argument in the most recent Matplotlib release.

Could do a conditional around matplotlib versions? Or could restrict which versions can be used?

Koncopd commented 2 years ago

The attached fix works on all versions.

ivirshup commented 2 years ago

Oh, I had assumed the test failures were related.

Any idea what's up with those?

Koncopd commented 2 years ago

No, i see the same test failures on the PR unrelated to plotting. No, i haven't looked yet.