Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Seaborn: How to add mean into boxplot visualization?

I was able to visualize my data in a boxplot using Seaborn.

sns.boxplot( x=df['Score'].astype('float'), y=df['Group'] )

The visualization shows me: all four quartiles, lower and upper whisker, and some outliers. How can I also add the Mean line into the boxplots? See current visualization (without mean).

enter image description here

Thanks!

like image 682
LaLaTi Avatar asked Sep 24 '18 21:09

LaLaTi


People also ask

How do you add a legend to a boxplot?

Make a box and whisker plot using boxplot() method with different facecolors. To place the legend, use legend() method with two boxplots, bp1 and bp2, and ordered label for legend elements. To display the figure, use show() method.

Does boxplot show mean or median?

The box covers the interquartile interval, where 50% of the data is found. The vertical line that split the box in two is the median. Sometimes, the mean is also indicated by a dot or a cross on the box plot.

How do you add a mean to a boxplot in python?

MatPlotLib with Python To show mean in a box plot, we can use showmeans=True in the argument of boxplot() method.

How do you visualize a boxplot in python?

Creating Box PlotThe matplotlib. pyplot module of matplotlib library provides boxplot() function with the help of which we can create box plots. The data values given to the ax. boxplot() method can be a Numpy array or Python list or Tuple of arrays.


1 Answers

I just figured it out. The code works like this:

sns.boxplot(x=df['Score'].astype('float'), y=df['Group'],showmeans=True )
like image 182
LaLaTi Avatar answered Sep 28 '22 01:09

LaLaTi