trevismd / statannotations

add statistical significance annotations on seaborn plots. Further development of statannot, with bugfixes, new features, and a different API.
Other
655 stars 73 forks source link

hide_non_significant kwarg should be configurable #127

Closed JasonMendoza2008 closed 1 year ago

JasonMendoza2008 commented 1 year ago

hide_non_significant optional kwarg was added to Annotator but wasn't made configurable. This PR aims at fixing this bug.

This worked:

from statannotations.Annotator import Annotator
import matplotlib.pyplot as plt
import seaborn as sns

sns.set(style="whitegrid")

df = sns.load_dataset("tips")

x = "day"
y = "total_bill"
order = ['Sun', 'Thur', 'Fri', 'Sat']
ax = sns.boxplot(data=df, x=x, y=y, order=order)
annot = Annotator(
    ax,
    [("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")],
    data=df,
    x=x,
    y=y,
    order=order,
    hide_non_significant=False
)
annot.configure(test='Mann-Whitney', text_format='star', loc='outside', verbose=2)
annot.apply_test()
ax, test_results = annot.annotate()

# show with big margins
plt.subplots_adjust(top=0.80)
plt.show()

This did not but should:

from statannotations.Annotator import Annotator
import matplotlib.pyplot as plt
import seaborn as sns

sns.set(style="whitegrid")

df = sns.load_dataset("tips")

x = "day"
y = "total_bill"
order = ['Sun', 'Thur', 'Fri', 'Sat']
ax = sns.boxplot(data=df, x=x, y=y, order=order)
annot = Annotator(
    ax,
    [("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")],
    data=df,
    x=x,
    y=y,
    order=order
)
annot.configure(test='Mann-Whitney', text_format='star', loc='outside', verbose=2, hide_non_significant=False)
annot.apply_test()
ax, test_results = annot.annotate()

# show with big margins
plt.subplots_adjust(top=0.80)
plt.show()

Both work after the PR. Tests were passed on Python 3.11.1.

I squashed everything like suggested last time I made a PR.

codecov[bot] commented 1 year ago

Codecov Report

Merging #127 (68750e8) into dev (4766703) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##              dev     #127   +/-   ##
=======================================
  Coverage   97.05%   97.05%           
=======================================
  Files          29       29           
  Lines        1936     1936           
=======================================
  Hits         1879     1879           
  Misses         57       57           
Files Changed Coverage Δ
statannotations/Annotator.py 91.48% <ø> (ø)
trevismd commented 1 year ago

Hello @JasonMendoza2008 , Thank you for the PR! I'm sorry I didn't check this sooner. In fact, I discovered it when I tried to update the documentation and add an example, and I implemented it independently. A few more changes were required as it shouldn't be an argument for Annotator's __init__ at all (because configuring once is also persistent if not updated), and there were no tests checking the parameter at all. I'm finalizing it and shipping it in v0.6.0. See you for the next one, I hope :)