Skip to content Skip to sidebar Skip to footer

How To Display Numeric Mean And Std Values Next To A Box Plot In A Series Of Box Plots?

I'm trying to display the value of mean and standard deviation next to my box plots in a plot of multiple box plots. Nothing is displayed when I try. #Boxplot 3 data3 =np.array([

Solution 1:

The boxplot method returns a dictionary that includes parts of the boxplot (whiskers, caps, boxes, medians, fliers, means). You can use these to add annotation at various location within the plot. Below I added mean and standard deviation values to the right of the median line:

Read this for more details Overlaying the numeric value of median/variance in boxplots

m1 = data3.mean(axis=0)
st1 = data3.std(axis=0)

fig, ax = plt.subplots()
bp = ax.boxplot(data3, showmeans=True)

for i, line inenumerate(bp['medians']):
    x, y = line.get_xydata()[1]
    text = ' μ={:.2f}\n σ={:.2f}'.format(m1[i], st1[i])
    ax.annotate(text, xy=(x, y))

which plots

enter image description here

Post a Comment for "How To Display Numeric Mean And Std Values Next To A Box Plot In A Series Of Box Plots?"