Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting with using scanpy.pl gives attribute error. #2680

Closed
2 of 3 tasks
Kiliankleemann opened this issue Oct 10, 2023 · 9 comments · Fixed by #2739
Closed
2 of 3 tasks

Plotting with using scanpy.pl gives attribute error. #2680

Kiliankleemann opened this issue Oct 10, 2023 · 9 comments · Fixed by #2739
Assignees
Labels

Comments

@Kiliankleemann
Copy link

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the master branch of scanpy.

What happened?

Plotting with scanpy.pl gives attribute error.

Minimal code sample

sc.pl.violin(adata, ["n_genes_by_counts", "total_counts", "pct_counts_mt"], jitter=0.4, multi_panel=True)

Error output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[47], line 1
----> 1 sc.pl.violin(adata, ["n_genes_by_counts", "total_counts", "pct_counts_mt"], jitter=0.4, multi_panel=True)

File ~/anaconda3/lib/python3.11/site-packages/scanpy/plotting/_anndata.py:795, in violin(adata, keys, groupby, log, use_raw, stripplot, jitter, size, layer, scale, order, multi_panel, xlabel, ylabel, rotation, show, save, ax, **kwds)
    790 if multi_panel and groupby is None and len(ys) == 1:
    791     # This is a quick and dirty way for adapting scales across several
    792     # keys if groupby is None.
    793     y = ys[0]
--> 795     g = sns.catplot(
    796         y=y,
    797         data=obs_tidy,
    798         kind="violin",
    799         scale=scale,
    800         col=x,
    801         col_order=keys,
    802         sharey=False,
    803         order=keys,
    804         cut=0,
    805         inner=None,
    806         **kwds,
    807     )
    809     if stripplot:
    810         grouped_df = obs_tidy.groupby(x)

File ~/anaconda3/lib/python3.11/site-packages/seaborn/categorical.py:2932, in catplot(data, x, y, hue, row, col, kind, estimator, errorbar, n_boot, units, seed, order, hue_order, row_order, col_order, col_wrap, height, aspect, log_scale, native_scale, formatter, orient, color, palette, hue_norm, legend, legend_out, sharex, sharey, margin_titles, facet_kws, ci, **kwargs)
   2929     linecolor = plot_kws.pop("linecolor", "auto")
   2930     linecolor = p._complement_color(linecolor, color, p._hue_map)
-> 2932     p.plot_violins(
   2933         width=width,
   2934         dodge=dodge,
   2935         gap=gap,
   2936         split=split,
   2937         color=color,
   2938         fill=fill,
   2939         linecolor=linecolor,
   2940         linewidth=linewidth,
   2941         inner=inner,
   2942         density_norm=density_norm,
   2943         common_norm=common_norm,
   2944         kde_kws=kde_kws,
   2945         inner_kws=inner_kws,
   2946         plot_kws=plot_kws,
   2947     )
   2949 elif kind == "boxen":
   2951     plot_kws = kwargs.copy()

File ~/anaconda3/lib/python3.11/site-packages/seaborn/categorical.py:1153, in _CategoricalPlotter.plot_violins(self, width, dodge, gap, split, color, fill, linecolor, linewidth, inner, density_norm, common_norm, kde_kws, inner_kws, plot_kws)
   1151 legend_artist = _get_patch_legend_artist(fill)
   1152 common_kws = {**plot_kws, "linewidth": linewidth, "edgecolor": linecolor}
-> 1153 self._configure_legend(ax, legend_artist, common_kws)

File ~/anaconda3/lib/python3.11/site-packages/seaborn/categorical.py:420, in _CategoricalPlotter._configure_legend(self, ax, func, common_kws, semantic_kws)
    418 if show_legend:
    419     self.add_legend_data(ax, func, common_kws, semantic_kws=semantic_kws)
--> 420     handles, _ = ax.get_legend_handles_labels()
    421     if handles:
    422         ax.legend(title=self.legend_title)

AttributeError: 'NoneType' object has no attribute 'get_legend_handles_labels'

Versions

Package                       Version
----------------------------- ---------------
aiobotocore                   2.6.0
aiohttp                       3.8.6
aioitertools                  0.11.0
aiosignal                     1.3.1
alabaster                     0.7.13
anaconda-anon-usage           0.4.2
anaconda-catalogs             0.2.0
anaconda-client               1.12.0
anaconda-cloud-auth           0.1.4
anaconda-navigator            2.5.0
anaconda-project              0.11.1
anndata                       0.10.1
anndata                       0.10.0rc1
annoy                         1.17.2
anyio                         4.0.0
appdirs                       1.4.4
argon2-cffi                   23.1.0
argon2-cffi-bindings          21.2.0
array-api-compat              1.4
array-api-compat              1.4
arrow                         1.3.0
astroid                       2.15.7
astropy                       5.3.4
asttokens                     2.4.0
async-lru                     2.0.4
async-timeout                 4.0.3
atomicwrites                  1.4.1
attrs                         23.1.0
Automat                       22.10.0
autopep8                      2.0.4
Babel                         2.12.1
backcall                      0.2.0
backports.functools-lru-cache 1.6.5
backports.tempfile            1.0
backports.weakref             1.0.post1
bcrypt                        4.0.1
beautifulsoup4                4.12.2
binaryornot                   0.4.4
black                         23.9.1
bleach                        6.1.0
blinker                       1.6.3
bokeh                         3.2.2
boltons                       23.0.0
botocore                      1.31.17
brotlipy                      0.7.0
cached-property               1.5.2
celltypist                    1.6.1
certifi                       2023.7.22
cffi                          1.16.0
chardet                       5.2.0
charset-normalizer            3.3.0
click                         8.1.7
cloudpickle                   2.2.1
clyent                        1.2.2
colorama                      0.4.6
colorcet                      3.0.1
comm                          0.1.4
conda                         23.9.0
conda-build                   3.27.0
conda-content-trust           0+unknown
conda_index                   0.2.3
conda-libmamba-solver         23.9.1
conda-pack                    0.6.0
conda-package-handling        2.2.0
conda_package_streaming       0.9.0
conda-repo-cli                1.0.75
conda-token                   0.4.0
conda-verify                  3.4.2
ConfigArgParse                1.7
connection-pool               0.0.3
constantly                    15.1.0
contourpy                     1.1.1
cookiecutter                  2.4.0
cryptography                  40.0.1
cssselect                     1.2.0
cycler                        0.12.1
cytoolz                       0.12.2
daal4py                       2023.2.1
dask                          2023.9.3
dataclasses                   0.8
datasets                      2.14.5
datashader                    0.15.2
datashape                     0.5.4
datrie                        0.8.2
debugpy                       1.8.0
decorator                     5.1.1
decoupler                     1.5.0
defusedxml                    0.7.1
diff-match-patch              20230430
dill                          0.3.7
distlib                       0.3.7
distributed                   2023.9.3
docopt                        0.6.2
docstring-to-markdown         0.12
docutils                      0.20.1
dpath                         2.1.6
entrypoints                   0.4
et-xmlfile                    1.1.0
exceptiongroup                1.1.3
executing                     1.2.0
fastjsonschema                2.18.1
filelock                      3.12.4
flake8                        6.0.0
Flask                         3.0.0
fonttools                     4.43.1
fqdn                          1.5.1
frozenlist                    1.4.0
fsspec                        2023.6.0
future                        0.18.3
gensim                        4.3.2
gitdb                         4.0.10
GitPython                     3.1.36
gmpy2                         2.1.2
greenlet                      3.0.0
h5py                          3.9.0
holoviews                     1.17.1
huggingface-hub               0.17.3
humanfriendly                 10.0
hvplot                        0.8.4
hyperlink                     21.0.0
idna                          3.4
igraph                        0.10.4
imagecodecs                   2023.1.23
imageio                       2.31.1
imagesize                     1.4.1
imbalanced-learn              0.11.0
importlib-metadata            6.8.0
importlib-resources           6.1.0
incremental                   22.10.0
inflection                    0.5.1
iniconfig                     2.0.0
intake                        0.7.0
intervaltree                  3.1.0
ipykernel                     6.25.2
ipython                       8.16.1
ipython-genutils              0.2.0
ipywidgets                    8.1.1
isoduration                   20.11.0
isort                         5.12.0
itemadapter                   0.8.0
itemloaders                   1.1.0
itsdangerous                  2.1.2
jaraco.classes                3.3.0
jedi                          0.18.1
jeepney                       0.8.0
jellyfish                     1.0.1
Jinja2                        3.1.2
jmespath                      1.0.1
joblib                        1.3.2
json5                         0.9.14
jsonpatch                     1.33
jsonpointer                   2.4
jsonschema                    4.19.1
jsonschema-specifications     2023.7.1
jupyter                       1.0.0
jupyter_client                8.3.1
jupyter-console               6.6.3
jupyter_core                  5.3.2
jupyter-events                0.7.0
jupyter-lsp                   2.2.0
jupyter_server                2.7.3
jupyter_server_terminals      0.4.4
jupyterlab                    4.0.6
jupyterlab-pygments           0.2.2
jupyterlab_server             2.25.0
jupyterlab-widgets            3.0.9
keyring                       24.2.0
kiwisolver                    1.4.5
lazy_loader                   0.3
lazy-object-proxy             1.9.0
leidenalg                     0.9.1
libarchive-c                  5.0
libmambapy                    1.5.1
linkify-it-py                 2.0.0
llvmlite                      0.40.1
locket                        1.0.0
lxml                          4.9.2
lz4                           4.3.2
Markdown                      3.5
markdown-it-py                3.0.0
MarkupSafe                    2.1.3
matplotlib                    3.8.0
matplotlib-inline             0.1.6
mccabe                        0.7.0
mdit-py-plugins               0.4.0
mdurl                         0.1.0
mistune                       3.0.1
mkl-service                   2.4.0
more-itertools                10.1.0
mpmath                        1.3.0
msgpack                       1.0.6
multidict                     6.0.4
multipledispatch              0.6.0
multiprocess                  0.70.15
munkres                       1.1.4
mypy-extensions               1.0.0
natsort                       8.4.0
natsort                       8.4.0
navigator-updater             0.4.0
nbclient                      0.8.0
nbconvert                     7.9.2
nbformat                      5.9.2
nest-asyncio                  1.5.6
networkx                      3.1
nltk                          3.8.1
notebook                      7.0.4
notebook_shim                 0.2.3
numba                         0.57.1
numexpr                       2.8.7
numpy                         1.24.4
numpydoc                      1.5.0
openpyxl                      3.1.2
overrides                     7.4.0
packaging                     23.2
pandas                        2.1.1
pandocfilters                 1.5.0
panel                         1.2.3
parallel-fastq-dump           0.6.7
param                         1.13.0
parsel                        1.8.1
parso                         0.8.3
partd                         1.4.1
pathspec                      0.11.2
patsy                         0.5.3
pep8                          1.7.1
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        10.0.1
pip                           23.2.1
pkce                          1.0.3
pkginfo                       1.9.6
pkgutil_resolve_name          1.3.10
plac                          1.3.5
platformdirs                  3.11.0
plotly                        5.17.0
pluggy                        1.3.0
ply                           3.11
pooch                         1.7.0
prometheus-client             0.17.1
prompt-toolkit                3.0.39
Protego                       0.3.0
psutil                        5.9.5
ptyprocess                    0.7.0
PuLP                          2.7.0
pure-eval                     0.2.2
py-cpuinfo                    9.0.0
pyarrow                       13.0.0
pyasn1                        0.5.0
pyasn1-modules                0.3.0
pycodestyle                   2.10.0
pycosat                       0.6.6
pycparser                     2.21
pyct                          0.4.6
pycurl                        7.45.1
pydantic                      1.10.13
pydeseq2                      0.4.1
PyDispatcher                  2.0.5
pydocstyle                    6.3.0
pyerfa                        2.0.0.3
pyflakes                      3.0.1
Pygments                      2.16.1
PyJWT                         2.8.0
pylint                        2.17.5
pylint-venv                   3.0.2
pyls-spyder                   0.4.0
pynndescent                   0.5.10
pyodbc                        4.0.39
pyOpenSSL                     23.2.0
pyparsing                     3.1.1
PyQt5-sip                     12.11.0
PySocks                       1.7.1
pytest                        7.4.2
python-dateutil               2.8.2
python-dotenv                 1.0.0
python-json-logger            2.0.7
python-lsp-black              1.3.0
python-lsp-jsonrpc            1.1.2
python-lsp-server             1.7.2
python-slugify                8.0.1
pytoolconfig                  1.2.5
pytz                          2023.3.post1
pyviz_comms                   3.0.0
PyWavelets                    1.4.1
pyxdg                         0.28
PyYAML                        6.0.1
pyzmq                         25.1.1
QDarkStyle                    3.1
qstylizer                     0.2.2
QtAwesome                     1.2.3
qtconsole                     5.4.4
QtPy                          2.4.0
queuelib                      1.6.2
referencing                   0.30.2
regex                         2023.10.3
requests                      2.31.0
requests-file                 1.5.1
requests-toolbelt             1.0.0
reretry                       0.11.8
rfc3339-validator             0.1.4
rfc3986-validator             0.1.1
rich                          13.6.0
rope                          1.10.0
rpds-py                       0.10.4
Rtree                         1.0.1
ruamel.yaml                   0.17.35
ruamel.yaml.clib              0.2.7
ruamel-yaml-conda             0.15.80
s3fs                          0.5.1
sacremoses                    0.0.53
safetensors                   0.3.3
scanpy                        1.9.5
scikit-image                  0.21.0
scikit-learn                  1.3.1
scikit-learn-intelex          20230725.122106
scipy                         1.11.3
Scrapy                        2.11.0
scrublet                      0.2.3
scTE                          1.0
scTE                          1.0
seaborn                       0.13.0
SecretStorage                 3.3.3
semver                        3.0.1
Send2Trash                    1.8.2
service-identity              18.1.0
session-info                  1.0.0
setuptools                    68.0.0
sip                           6.6.2
six                           1.16.0
smart-open                    6.4.0
smmap                         5.0.0
snakemake                     7.32.3
sniffio                       1.3.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
soupsieve                     2.5
Sphinx                        7.2.6
sphinxcontrib-applehelp       1.0.7
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.4
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.6
sphinxcontrib-serializinghtml 1.1.9
spyder                        5.4.3
spyder-kernels                2.4.4
SQLAlchemy                    2.0.21
stack-data                    0.6.2
statsmodels                   0.14.0
stdlib-list                   0.8.0
stopit                        1.1.2
sympy                         1.12
tables                        3.9.1
tabulate                      0.9.0
TBB                           0.2
tblib                         2.0.0
tenacity                      8.2.3
terminado                     0.17.1
text-unidecode                1.3
textdistance                  4.5.0
texttable                     1.7.0
threadpoolctl                 3.2.0
three-merge                   0.1.1
throttler                     1.2.2
tifffile                      2023.4.12
tinycss2                      1.2.1
tldextract                    3.6.0
tokenizers                    0.14.0
toml                          0.10.2
tomli                         2.0.1
tomlkit                       0.12.1
toolz                         0.12.0
toposort                      1.10
tornado                       6.3.3
tqdm                          4.66.1
traitlets                     5.11.2
transformers                  4.34.0
truststore                    0.8.0
Twisted                       22.10.0
types-python-dateutil         2.8.19.14
typing_extensions             4.8.0
typing-utils                  0.1.0
tzdata                        2023.3
uc-micro-py                   1.0.1
ujson                         5.8.0
umap-learn                    0.5.4
uri-template                  1.3.0
urllib3                       1.26.15
virtualenv                    20.24.5
w3lib                         2.1.2
watchdog                      3.0.0
wcwidth                       0.2.8
webcolors                     1.13
webencodings                  0.5.1
websocket-client              1.6.4
Werkzeug                      3.0.0
whatthepatch                  1.0.5
wheel                         0.38.4
widgetsnbextension            4.0.9
wrapt                         1.15.0
wurlitzer                     3.0.3
xarray                        2023.9.0
xxhash                        3.4.1
xyzservices                   2023.10.0
yapf                          0.24.0
yarl                          1.9.2
yte                           1.5.1
zict                          3.0.0
zipp                          3.17.0
zope.interface                6.1
zstandard                     0.21.0

@hanhanele
Copy link

I also have encountered this same error when trying to use sc.pl.violin

@JacquesFGD
Copy link

JacquesFGD commented Oct 13, 2023

I have the same error on scanpy 1.9.5, seaborn 0.13.0, the error seems to be specific to 'multi_panel = True' and produces 3 empty graphs that all inherit the "n_genes_by_counts" x-label instead of the proper one.
The same graph is produced normally with 'multi_panel = False'.

sc.pl.violin(full_adata, ['n_genes_by_counts', 'total_counts', 'pct_counts_MT'], multi_panel=True, stripplot=False)

@bbimber
Copy link

bbimber commented Oct 13, 2023

We're also hitting this. I didnt test this yet, but from our CI history it seems like this worked with seaborn-0.12.2, but broke when that updated to seaborn-0.13.0

@eroell
Copy link
Contributor

eroell commented Oct 14, 2023

Hey,
thanks a lot for raising this @Kiliankleemann! And thanks a lot for showing the Version details, big help here.

I'll look into this, for the moment it appears that for the violin plot

  • indeed as @JacquesFGD mentioned it seems that using seaborn-0.13.0 raises this error when setting multi_panel=True: the plot obtainable from multi_panel=False seems to work.
  • as @bbimber noted, using seaborn-0.12.2 seems to work, also with the multi_panel=True option.

For urgent violin plots, either of these two options should produce them. Will get back to this asap.

@eroell eroell self-assigned this Oct 14, 2023
@eroell
Copy link
Contributor

eroell commented Oct 16, 2023

Hey,

indeed there seems to be an issue with our current usage of seaborn, not working with seaborn 0.13.0.
This has been fixed on the main branch here, and we'll eventually take over the newest seaborn version once this is cleared.

For users running into this issue now

  • first check if you indeed have seaborn 0.13.0. If yes, then do
  • pip install seaborn==0.12.2 if using pip or
  • conda install seaborn=0.12.2 if using conda

this makes sure you are using the working version of seaborn.

Hope this helps!

@Kiliankleemann
Copy link
Author

Thank you so much!

@eroell
Copy link
Contributor

eroell commented Nov 2, 2023

Hey @victorlga are you still interested in fixing this? :)
I think deleting the line order=keys where catplot is used should do the trick, then also the seaborn dependency could be loosened to allow for 0.13.0...
What do you think?

@eroell eroell mentioned this issue Nov 9, 2023
3 tasks
@jowodo
Copy link

jowodo commented Nov 15, 2023

Hi,
thanks for fixing this task so quickly! When would you estimate that a new release comes (to pypi) which allows for seaborn>=0.13.0?

Thanks!

@flying-sheep
Copy link
Member

We sped up our release process, which means it’s not a huge deal to make one. But it’s still more than just clicking a button, so since we just made a release, maybe in 1-2 weeks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants