Organizational Research By

Surprising Reserch Topic

overlapping boxplots in python using -'python,pandas,boxplot'


overlapping boxplots in python  using -'python,pandas,boxplot'

I have the foll. dataframe:

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


and want to plot a boxplot where the x-axis is 'Av_Temp' divided into equi-sized bins (say 2 in this case), and the Y-axis shows the corresponding range of values for Tot_Precip. I have the foll. code (thanks to Find pandas quartiles based on another column), however, when I plot the boxplots, they are getting plotted one on top of another. Any suggestions?

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()



    
asked Sep 7, 2015 by rajesh
0 votes
8 views



Related Hot Questions



Government Jobs Opening


...