我试图在多个箱形图的图中显示均值和标准差的值。我尝试时没有显示任何内容。
#Boxplot 3
data3 =np.array([[ 4.38, 3.27, 6.07],
[ 4.35, 3.51, 6.14],
[ 4.09, 3.33, 5.92],
[ 4.9 , 3.97, 5.02],
[ 4.56, 3.5 , 4.5 ],
[ 4.78, 3.95, 4.58]])
fig3 = plt.figure(3)
ax3 = fig3.add_subplot(111)
ax3.boxplot(data3, showmeans=True)
ax3.set_title('Serve - Data Location and Variance 1',fontsize=15,fontweight='bold', y=1.06)
ax3.set_ylabel('Velocity [m/s]',fontsize=11.5)
ax3.set_xlabel('Parameter',fontsize=11.5)
ax3.set_xticklabels(['V_in', 'V_out', 'V_bat'],style='italic')
ax3.get_xaxis().tick_bottom()
ax3.get_yaxis().tick_left()
m1=data3.mean(axis=0) #Mean values
mL1 = [str(np.round(s, 2)) for s in m1]
st1=data3.std(axis=0) #Standard deviation values
sT1=[str(np.round(s, 2)) for s in st1]
ind=0
for i in range (len(ax3.get_xticklabels())):
ax3.text(i, m1[ind]+1, mL1[ind], horizontalalignment='center', color='w', weight='semibold')
ind+=1
最佳答案
boxplot
方法返回一个字典,其中包含部分箱线图( mustache 、帽、框、中位数、传单、均值)。您可以使用它们在图中的不同位置添加注释。下面我在中线右侧添加了均值和标准差值:
阅读此了解更多详情 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 in enumerate(bp['medians']):
x, y = line.get_xydata()[1]
text = ' μ={:.2f}\n σ={:.2f}'.format(m1[i], st1[i])
ax.annotate(text, xy=(x, y))
哪些地 block
关于python - 如何在一系列箱形图中的箱形图旁边显示数值平均值和标准值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58066009/