statannotations icon indicating copy to clipboard operation
statannotations copied to clipboard

Allow to add title

Open JohannesWiesner opened this issue 2 years ago • 4 comments

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.

JohannesWiesner avatar Apr 06 '23 10:04 JohannesWiesner

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

trevismd avatar Apr 16 '23 09:04 trevismd

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

JohannesWiesner avatar Apr 18 '23 09:04 JohannesWiesner

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.

JohannesWiesner avatar Jun 01 '23 09:06 JohannesWiesner

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

trevismd avatar Jun 09 '23 07:06 trevismd