Skip to content

Unit tests fail with latest version of seaborn #1420

Closed

Description

@WeilerP

Description

Using the seaborn==0.11 makes scanpy/tests/test_plotting.py:test_violin and scanpy/tests/notebooks/test_pbmc3k.py fail. The warning

UserWarning: Vertical orientation ignored with only `x` specified.

is thrown by seaborn in the stack trace for the failed tests.

The problem seems to originate from here and here, where x and y are not both specified.

See #1417 and especially this comment by @fidelram for more details.

Activity

  1. fidelram commented on Sep 17, 2020

    @fidelram
    Collaborator

    @WeilerP Any idea on how to solve the problem? I thought that setting orient='vertical' was going to solve the issue but we already do that.

  2. WeilerP commented on Sep 17, 2020

    @WeilerP
    ContributorAuthor

    I skimmed through the code only briefly yesterday but I think the problem might be that both x and y need to be specified: The error message seems to indicate so and the two lines seemingly responsible for the problem are the only ones where x and y are not both specified.

    I'll have a closer look at it in a bit.

  3. fidelram commented on Sep 17, 2020

    @fidelram
    Collaborator
  4. WeilerP commented on Sep 17, 2020

    @WeilerP
    ContributorAuthor

    Yes, I saw that too but I was hoping it could be prevented as it seems suboptimal to me and is probably confusing when looking at the code.

    Is there a specific reason for using seaborn.FacetGrid instead of seaborn.catplot (see here)? Replacing the lines

    # ...
    kwds.setdefault('cut', 0)
    kwds.setdefault('inner')
    
    if multi_panel and groupby is None and len(ys) == 1:
        # This is a quick and dirty way for adapting scales across several
        # keys if groupby is None.
        y = ys[0]
        g = sns.FacetGrid(obs_tidy, col=x, col_order=keys, sharey=False)
    
        # don't really know why this gives a warning without passing `order`
        g = g.map(sns.violinplot, y, orient='vertical', scale=scale, order=keys, **kwds)

    here by

    if multi_panel and groupby is None and len(ys) == 1:
        g = sns.catplot(y=y, data=obs_tidy, kind="violin", col=x, col_order=keys, sharey=False, order=keys, **kwds)

    gives the desired plot (except for different size). The strip plot can be added on top by calling seaborn.stripplot afterwards:

    if multi_panel and groupby is None and len(ys) == 1:
        g = sns.catplot(y=y, data=obs_tidy, kind="violin", col=x, col_order=keys, sharey=False, order=keys, **kwds)
        if stripplot:
            sns.stripplot(y=y, data=obs_tidy, jitter=jitter, color="black")

    At the moment, I am just unsure how to plot to each subplot of the new g. It might be possible to loop through the plot grid so not to add everything on top of the last plot.

    master_violin_multi_panel

    Besides the not yet solved strip plot problem, would that be a valid alternative?

  5. fidelram commented on Sep 17, 2020

    @fidelram
    Collaborator

    There is not particular reason to use FacetGrid. If catplot does the job then it is ok.

  6. WeilerP commented on Sep 17, 2020

    @WeilerP
    ContributorAuthor

    The following code produces the desired plot (up to permutation of the subplots and the image size) in case of only one row of subplots:

    if multi_panel and groupby is None and len(ys) == 1:
        # This is a quick and dirty way for adapting scales across several
        # keys if groupby is None.
        y = ys[0]
    
        g = sns.catplot(y=y, data=obs_tidy, kind="violin", col=x, col_order=keys, sharey=False, order=keys, **kwds)
    
        if stripplot:
            grouped_df = obs_tidy.groupby(x)
            for ax_id, key in zip(range(g.axes.shape[1]), keys):
                sns.stripplot(y=y, data=grouped_df.get_group(key), jitter=jitter, size=size, color="black", ax=g.axes[0, ax_id], **kwds)

    master_violin_multi_panel

    Seems a bit hacky to me. What do you think @fidelram?

  7. fidelram commented on Sep 17, 2020

    @fidelram
    Collaborator

    @WeilerP probably there is a more direct way to overlay the stripplot but I don't think that it makes any big difference.

    Can you make a PR to see how the tests work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions