<jupyter_start><jupyter_text>Boxplot non-hue<jupyter_code>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)
add_stat_annotation(ax, data=df, x=x, y=y, order=order,
                    boxPairList=[("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")],
                    test='Mann-Whitney', textFormat='star', loc='outside', verbose=2)
plt.savefig('example1.png', dpi=300, bbox_inches='tight')<jupyter_output>pvalue annotation legend:
ns: 5.00e-02 < p <= 1.00e+00
*: 1.00e-02 < p <= 5.00e-02
**: 1.00e-03 < p <= 1.00e-02
***: 1.00e-04 < p <= 1.00e-03
****: p <= 1.00e-04

Thur v.s. Fri: MWW RankSum two-sided P_val=6.477e-01 U_stat=6.305e+02
Thur v.s. Sat: MWW RankSum two-sided P_val=4.690e-02 U_stat=2.180e+03
Fri v.s. Sun: MWW RankSum two-sided P_val=2.680e-02 U_stat=4.835e+02<jupyter_text>Boxplot with hue<jupyter_code>x = "day"
y = "total_bill"
hue = "smoker"
ax = sns.boxplot(data=df, x=x, y=y, hue=hue)
add_stat_annotation(ax, data=df, x=x, y=y, hue=hue,
                    boxPairList=[(("Thur", "No"), ("Fri", "No")),
                                 (("Sat", "Yes"), ("Sat", "No")),
                                 (("Sun", "No"), ("Thur", "Yes"))
                                ],
                    test='t-test_ind', textFormat='full', loc='inside', verbose=2)
plt.legend(loc='upper left', bbox_to_anchor=(1.03, 1))
plt.savefig('example2.png', dpi=300, bbox_inches='tight')<jupyter_output>Thur_No v.s. Fri_No: t-test independent samples, P_val=7.425e-01 stat=-3.305e-01
Sat_Yes v.s. Sat_No: t-test independent samples, P_val=4.304e-01 stat=7.922e-01
Sun_No v.s. Thur_Yes: t-test independent samples, P_val=5.623e-01 stat=5.822e-01<jupyter_text>Boxplot with bucketed categories<jupyter_code>df['tip_bucket'] = pd.cut(df['tip'], 3)
df.head()
tip_bucket_list = df['tip_bucket'].unique()
tip_bucket_list
x = "day"
y = "total_bill"
hue = "tip_bucket"
data = df
ax = sns.boxplot(data=df, x=x, y=y, hue=hue)
boxPlotter = sns.categorical._BoxPlotter(x, y, hue, data, order, hue_order=None,
                                         orient=None, width=.8, color=None, palette=None, saturation=.75,
                                         dodge=True, fliersize=5, linewidth=None)
add_stat_annotation(ax, data=df, x=x, y=y, hue=hue,
                    boxPairList=[(("Sat", tip_bucket_list[2]), ("Fri", tip_bucket_list[0]))],
                    test='t-test_ind', loc='inside', verbose=2)
plt.legend(loc='upper left', bbox_to_anchor=(1.03, 1))<jupyter_output>pvalue annotation legend:
ns: 5.00e-02 < p <= 1.00e+00
*: 1.00e-02 < p <= 5.00e-02
**: 1.00e-03 < p <= 1.00e-02
***: 1.00e-04 < p <= 1.00e-03
****: p <= 1.00e-04

Sat_(7.0, 10.0] v.s. Fri_(0.991, 4.0]: t-test independent samples, P_val=6.176e-07 stat=7.490e+00<jupyter_text>Tuning y offsets<jupyter_code>x = "day"
y = "total_bill"
hue = "smoker"
ax = sns.boxplot(data=df, x=x, y=y, hue=hue)
add_stat_annotation(ax, data=df, x=x, y=y, hue=hue,
                    boxPairList=[(("Thur", "No"), ("Fri", "No")),
                                 (("Sat", "Yes"), ("Sat", "No")),
                                 (("Sun", "No"), ("Thur", "Yes"))
                                ],
                    test='t-test_ind', textFormat='full', loc='inside',
                    lineYOffsetToBoxAxesCoord=0.2, lineYOffsetAxesCoord=0.02,
                    lineHeightAxesCoord=0.02, textYOffsetPoints=2,
                    verbose=2)
plt.legend(loc='upper left', bbox_to_anchor=(1.03, 1))<jupyter_output>Thur_No v.s. Fri_No: t-test independent samples, P_val=7.425e-01 stat=-3.305e-01
Sat_Yes v.s. Sat_No: t-test independent samples, P_val=4.304e-01 stat=7.922e-01
Sun_No v.s. Thur_Yes: t-test independent samples, P_val=5.623e-01 stat=5.822e-01
{'fraction_non_alphanumeric': 0.19047619047619047, 'fraction_numerical': 0.06828885400313972, 'mean_word_length': 2.941237113402062, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '268117', 'license': 'MIT', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1541, 'n_words': 284, 'path': 'example/example.ipynb', 'repo_name': 'annabaiad/statannot', 'size': '3822'}