我在绘制箱形图的中位数和均值点时遇到问题。我尝试了几种方法。这是我的代码。
import pandas as pd
import numpy as np
import statistics
from matplotlib import pyplot as plt
a=pd.read_excel('Book1.xlsx')
b=a['HH'][0:744].values
c=a['BC880'][0:744].values
d=[]
f=[]
k=[]
z=[]
x=list(range(24))
fig=plt.figure()
i=0
j=0
for j in range(0,24):
for i in range(0,744):
if j==b[i]:
d.append(c[i])
d=[d for d in d if str(d)!='nan']
m=np.average(d)
s=statistics.stdev(d)
f.append(d)
B=plt.boxplot(f,showfliers=False,showmeans=True,whis=[5,95])
res = {key : [v.get_data() for v in value] for key, value in B.items()}
t=res.get('medians')
u=res.get('means')
k.append(m)
z.append(s)
d=[]
print(f,'\n','Average values are ',k,'\n','Standard deviations are ',z)
plt.title('Variation of BC880 concentration in Dec2018')
plt.xlabel('Hours')
plt.ylabel('Concentration of BC880 in ngm^-3')
plt.savefig('BC880 Concentration wrt hours-boxplot')
fig.set_figheight(5)
fig.set_figwidth(10)
我尝试从箱形图访问平均值和中值。但是我无法做到。请帮忙。