1
我有這個foll。數據幀:python中的重疊盒圖
Av_Temp Tot_Precip
278.001 0
274 0.0751864
270.294 0.631634
271.526 0.229285
272.246 0.0652201
273 0.0840059
270.463 0.0602944
269.983 0.103563
268.774 0.0694555
269.529 0.010908
270.062 0.043915
271.982 0.0295718
和要繪製的箱線圖,其中x軸是「Av_Temp」(在這種情況下比如說2)劃分成相等大小的二進制位,並且Y軸示出了用於相應的值的範圍Tot_Precip。我有這個foll。代碼(感謝Find pandas quartiles based on another column),但是,當我繪製箱形圖時,它們被繪製成一個在另一個之上。有什麼建議麼?
expl_var = 'Av_Temp'
cname = 'Tot_Precip'
df[expl_var+'_Deciles'] = pandas.qcut(df[expl_var], 2)
grp_df = df.groupby(expl_var+'_Deciles').apply(lambda x: numpy.array(x[cname]))
fig, ax = plt.subplots()
for i in range(len(grp_df)):
box_arr = grp_df[i]
box_arr = box_arr[~numpy.isnan(box_arr)]
stats = cbook.boxplot_stats(box_arr, labels = str(i))
ax.bxp(stats)
ax.set_yscale('log')
plt.show()