trevismd / statannotations

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

Allow to add title #119

Open JohannesWiesner opened 1 year ago

JohannesWiesner commented 1 year ago

It would be nice to be able to add a plot title on top of all the annotations. Something like:

statannotations.Annotator.Annotator.configure(title='foobar',...)

I guess the function would somehow have to take into account if annotations are to the left and the right (in this case the top is free and the title can be simpled added by using ax.set_tile('foobar')). If the annotations are on the top then the function would have to check where the upper end of the annotations lies and put the title there.

trevismd commented 1 year ago

Doesn't plt.title work in all cases? The parameter could be a shortcut to that when one does not need more customization?

JohannesWiesner commented 1 year ago

In my case plt.title() is "agnostic" to the annotations generated by statannotations which leads to an overlap on top of the plot.

JohannesWiesner commented 1 year ago

Example:

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

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)
pairs=[("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")]
annotator = Annotator(ax, pairs, data=df, x=x, y=y, order=order)
annotator.configure(test='Mann-Whitney', text_format='star', loc='outside')
annotator.apply_and_annotate()
plt.title('tips')

image As you can see plt.title() is not "aware" of the fact that there are already annotations generated by statannotations and therefore will just brute-force plot the title on top of the annotations.

trevismd commented 1 year ago

Your case is clear, it's a valid request!