Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, Seaborn - How to add significance bars and asterisks to boxplots

Tags:

python

seaborn

I'm looking for suggestions on how to add significance bars between boxes on a box plot and also have asterisks representing significance. I am using seaborn to create plots and I couldn't find any common methods for accomplishing this. Nothing stuck out to me in the documentation but I am a novice and new to matplotlib in general so I wouldn't be surprised if I overlooked something.

I would like to be able to do something similar to this plot using R, but with python

like image 497
Chris Avatar asked Jun 08 '16 15:06

Chris


1 Answers

@UlrichStern suggested an answer to a previous question that does exactly what I need.

How does one insert statistical annotations (stars or p-values) into matplotlib / seaborn plots?

In layman terms, you plot a line with four x values and four y values.

plt.plot([x1,x1, x2, x2], [y1, y2, y2, y1], linewidth=1, color='k')

The magic for me was here:

[x1, x1, x2, x2]
[y1, y2, y2, y1]

x1 should be the location of whatever box you want to point to and x2 should be the other box you want to point to.

y2 should be where you want the line on the y-axis and y1 is how far down you want the vertical ticks on each end to extend.

like image 187
Chris Avatar answered Oct 03 '22 15:10

Chris