12

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

Community
  • 1
  • 1
Chris
  • 1,100
  • 3
  • 13
  • 27
  • use the native drawing methods of the matplotlib object that seaborn created. – Paul H Jun 15 '16 at 14:04
  • Can you expound on that further? I'm not sure I understand what that means. What I've been doing is plotting 3 lines for each significant value. Basically a long horizontal line and two small vertical "ticks" at each end. Then using annotate for the asterisks. – Chris Jun 15 '16 at 15:10
  • use the annotation method of the axes object: http://matplotlib.org/examples/pylab_examples/annotation_demo2.html – Paul H Jun 15 '16 at 16:31
  • 2
    My [answer](http://stackoverflow.com/a/37518947/1628638) to a similar question should have exactly what you are looking for. – Ulrich Stern Jun 22 '16 at 17:05
  • @UlrichStern Oh this is great, thanks! – Chris Jun 22 '16 at 17:40

1 Answers1

5

@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.

Community
  • 1
  • 1
Chris
  • 1,100
  • 3
  • 13
  • 27