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

Cannot configure annotator for plot when groups are in y axis #113

Open
jonpedros opened this issue Mar 6, 2023 · 1 comment
Open

Cannot configure annotator for plot when groups are in y axis #113

jonpedros opened this issue Mar 6, 2023 · 1 comment

Comments

@jonpedros
Copy link

jonpedros commented Mar 6, 2023

I think I might be doing something wrong here, but...

import seaborn as sns
from statannotations.Annotator import Annotator

iris = sns.load_dataset("iris")
iris = pd.melt(iris, "species", var_name="measurement")
pair_list = [(('sepal_length', 'setosa'),
              ('sepal_length', 'versicolor'),
              ('sepal_length', 'virginica')),
             (('sepal_width', 'setosa'),
              ('sepal_width', 'versicolor'),
              ('sepal_width', 'virginica')),
             (('petal_length', 'setosa'),
              ('petal_length', 'versicolor'),
              ('petal_length', 'virginica')),
             (('petal_width', 'setosa'),
              ('petal_width', 'versicolor'),
              ('petal_width', 'virginica'))]
petal_ax = sns.pointplot(
    data=iris, x="value", y="measurement", hue="species",
    join=False, dodge=.8 - .8 / 3, palette="dark",
    markers="d", scale=.75, errorbar=None
)
annotator = Annotator(ax=petal_ax, 
                        pairs=pair_list, 
                        data=iris, 
                        y="measurement",
                        x="value",
                        hue="species", 
                        order=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'],
                        hue_order=['setosa', 'versicolor', 'virginica'])
annotator.configure(test='Mann-Whitney', text_format='star', loc='outside')
annotator.apply_and_annotate()

Returns

ValueError                                Traceback (most recent call last)
[c:\Users\systemses\Downloads\pyControl\running_analysis](file:///C:/Users/systemses/Downloads/pyControl/running_analysis)[rand].ipynb Cell 9 in 2
      [3](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=2) pair_list = [(('sepal_length', 'setosa'),
      [4](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=3)               ('sepal_length', 'versicolor'),
      [5](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=4)               ('sepal_length', 'virginica')),
   (...)
     [13](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=12)               ('petal_width', 'versicolor'),
     [14](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=13)               ('petal_width', 'virginica'))]
     [15](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=14) petal_ax = sns.pointplot(
     [16](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=15)     data=iris, x="value", y="measurement", hue="species",
     [17](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=16)     join=False, dodge=.8 - .8 / 3, palette="dark",
     [18](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=17)     markers="d", scale=.75, errorbar=None
     [19](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=18) )
---> [20](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=19) annotator = Annotator(ax=petal_ax, 
     [21](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=20)                         pairs=pair_list, 
     [22](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=21)                         data=iris, 
     [23](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=22)                         y="measurement",
     [24](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=23)                         x="value",
     [25](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=24)                         hue="species", 
     [26](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=25)                         order=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'],
     [27](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=26)                         hue_order=['setosa', 'versicolor', 'virginica'])
     [28](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=27) annotator.configure(test='Mann-Whitney', text_format='star', loc='outside')
     [29](vscode-notebook-cell:/c%3A/Users/systemses/Downloads/pyControl/running_analysis%5Brand%5D.ipynb#X42sZmlsZQ%3D%3D?line=28) annotator.apply_and_annotate()
...
---> 63     raise ValueError(f"Missing x value(s) "
     64                      f"`{render_collection(unmatched_in_order)}` in {x} "
     65                      f"(specified in `order`)")

ValueError: Missing x value(s) `"sepal_width", "petal_length", "sepal_length", "petal_width"` in value (specified in `order`)
@trevismd
Copy link
Owner

trevismd commented Mar 8, 2023

Hello! I can see that your pair_list is a list of 3-tuples, which isn't the expected format to define the groups to compare. It should look like this instead:

pair_list = [
    (('sepal_length', 'setosa'), ('sepal_length', 'versicolor')),
    (('sepal_length', 'virginica')), ('sepal_width', 'setosa')),
    (('sepal_width', 'versicolor'), ('sepal_width', 'virginica')),
    (('petal_length', 'setosa'), ('petal_length', 'versicolor')),
    ...
]

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

No branches or pull requests

2 participants