A Python package to add p-value annotations on plots generated with Seaborn. Pvalannot is inspired by the magnificent package statannotations. The major feature of pvalannot is the support of user-input statistical function (default is Wilcoxon ranksum test) and user-defined p-value text format.
- Clone the GitHub repo, e.g. with
git clone https://github.com/mourisl/pvalannot
. - Copy "pvalannot" folder to your project folder or run "python3 setup.py install" to install..
I will try to add pvalannot to PyPi in future.
Here is a minimal example:
import matplotlib.pyplot as plt
import seaborn as sns
from pvalannot import pvalannot
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)
pvalannot.AddPvalAnnot(x=x, y=y, data=df, order=order)
AddPvalAnnot takes arguments for user-defined features:
- func: User-defined statistical function. The function takes two arguments arrays x, y. The function should return two numbers, first is statistical number (positive: x<y, negative: x>y) and test p-value. Default func=scipy.stats.wilcoxon .
- fmt: The format of p-value to show. This follows Python format string convention, for example fmt="%.2e" will output p-values in two digits scientific notation.
See more examples in dev.ipynb.
- Python >= 3.6
- seaborn >= 0.9
- matplotlib >= 2.2.2
- scipy >= 1.1.0