Remember
Register
All Activity
Tags
Users
Ask a Question
About Boostr
Advertise on boostr.in
Jobs
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()
Â Â Â Â
python
pandas
boxplot
asked
Sep 7, 2015
by
rajesh
Please
log in
or
register
to add a comment.
0
votes
9
views
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or
register
.
...