X-Received: by 10.180.36.234 with SMTP id t10mr866647wij.1.1402045864851; Fri, 06 Jun 2014 02:11:04 -0700 (PDT) X-Received: by 10.140.27.244 with SMTP id 107mr19741qgx.18.1402045864795; Fri, 06 Jun 2014 02:11:04 -0700 (PDT) Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!10no18693118lbg.0!news-out.google.com!k18ni5969qav.1!nntp.google.com!j5no1902268qaq.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Fri, 6 Jun 2014 02:11:04 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=151.170.240.10; posting-account=4ZFvUQoAAADRMMFTP4AD3zzRxG7Xhtl3 NNTP-Posting-Host: 151.170.240.10 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7020af81-e4eb-4dcb-9e7a-ce2eb98b2b1c@googlegroups.com> Subject: Overlaying a boxplot onto a time series figure From: Jamie Mitchell Injection-Date: Fri, 06 Jun 2014 09:11:04 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.python:72826 Hi there, I would like to overlay some boxplots onto a time series. I have tried pylab.hold(True) in between the two plots in my code but this hasn't worked. The problem is that the x-axes of the boxplots and the time series are not the same. Code for time series: python2.7 import netCDF4 import matplotlib.pyplot as plt import numpy as np swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:] year_con=swh_Q0_con_sw.variables['year'][:] swh_Q3_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q3_con_sw=swh_Q3_con_sw.variables['hs'][:] swh_Q4_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q4_con_sw=swh_Q4_con_sw.variables['hs'][:] swh_Q14_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q14_con_sw=swh_Q14_con_sw.variables['hs'][:] swh_Q16_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r') hs_Q16_con_sw=swh_Q16_con_sw.variables['hs'][:] swh_Q0_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q0_fut_sw=swh_Q0_fut_sw.variables['hs'][:] year_fut=swh_Q0_fut_sw.variables['year'][:] swh_Q3_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q3_fut_sw=swh_Q3_fut_sw.variables['hs'][:] swh_Q4_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q4_fut_sw=swh_Q4_fut_sw.variables['hs'][:] swh_Q14_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q14_fut_sw=swh_Q14_fut_sw.variables['hs'][:] swh_Q16_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r') hs_Q16_fut_sw=swh_Q16_fut_sw.variables['hs'][:] fit_Q0_con_sw=np.polyfit(year_con,hs_Q0_con_sw,1) fit_fn_Q0_con_sw=np.poly1d(fit_Q0_con_sw) plt.plot(year_con,hs_Q0_con_sw,'g.') plt.plot(year_con,fit_fn_Q0_con_sw(year_con),'g',label='Q0 no pert') fit_Q3_con_sw=np.polyfit(year_con,hs_Q3_con_sw,1) fit_fn_Q3_con_sw=np.poly1d(fit_Q3_con_sw) plt.plot(year_con,hs_Q3_con_sw,'b.') plt.plot(year_con,fit_fn_Q3_con_sw(year_con),'b',label='Q3 low sens') fit_Q4_con_sw=np.polyfit(year_con,hs_Q4_con_sw,1) fit_fn_Q4_con_sw=np.poly1d(fit_Q4_con_sw) plt.plot(year_con,hs_Q4_con_sw,'y.') plt.plot(year_con,fit_fn_Q4_con_sw(year_con),'y',label='Q4 low sens') fit_Q14_con_sw=np.polyfit(year_con,hs_Q14_con_sw,1) fit_fn_Q14_con_sw=np.poly1d(fit_Q14_con_sw) plt.plot(year_con,hs_Q14_con_sw,'r.') plt.plot(year_con,fit_fn_Q14_con_sw(year_con),'r',label='Q14 high sens') fit_Q16_con_sw=np.polyfit(year_con,hs_Q16_con_sw,1) fit_fn_Q16_con_sw=np.poly1d(fit_Q16_con_sw) plt.plot(year_con,hs_Q16_con_sw,'c.') plt.plot(year_con,fit_fn_Q16_con_sw(year_con),'c',label='Q16 high sens') fit_Q0_fut_sw=np.polyfit(year_fut,hs_Q0_fut_sw,1) fit_fn_Q0_fut_sw=np.poly1d(fit_Q0_fut_sw) plt.plot(year_fut,hs_Q0_fut_sw,'g.') plt.plot(year_fut,fit_fn_Q0_fut_sw(year_fut),'g') fit_Q3_fut_sw=np.polyfit(year_fut,hs_Q3_fut_sw,1) fit_fn_Q3_fut_sw=np.poly1d(fit_Q3_fut_sw) plt.plot(year_fut,hs_Q3_fut_sw,'b.') plt.plot(year_fut,fit_fn_Q3_fut_sw(year_fut),'b') fit_Q4_fut_sw=np.polyfit(year_fut,hs_Q4_fut_sw,1) fit_fn_Q4_fut_sw=np.poly1d(fit_Q4_fut_sw) plt.plot(year_fut,hs_Q4_fut_sw,'y.') plt.plot(year_fut,fit_fn_Q4_fut_sw(year_fut),'y') fit_Q14_fut_sw=np.polyfit(year_fut,hs_Q14_fut_sw,1) fit_fn_Q14_fut_sw=np.poly1d(fit_Q14_fut_sw) plt.plot(year_fut,hs_Q14_fut_sw,'r.') plt.plot(year_fut,fit_fn_Q14_fut_sw(year_fut),'y') fit_Q16_fut_sw=np.polyfit(year_fut,hs_Q16_fut_sw,1) fit_fn_Q16_fut_sw=np.poly1d(fit_Q16_fut_sw) plt.plot(year_fut,hs_Q16_fut_sw,'c.') plt.plot(year_fut,fit_fn_Q16_fut_sw(year_fut),'c') plt.legend(loc='best') plt.xlabel('Year') plt.ylabel('Significant Wave Height annual averages SW England') plt.title('Time series of Significant Wave Height') plt.show() Code for boxplots: python2.7 from pylab import * import netCDF4 data=(hs_Q0_con_sw,hs_Q3_con_sw,hs_Q4_con_sw,hs_Q14_con_sw,hs_Q16_con_sw) figure(1) boxplot(data) labels=('QO no pert','Q3 low sens','Q4 low sens','Q14 high sens','Q16 high sens') xticks(range(1,6),labels,rotation=15) xlabel('Ensemble Member') ylabel('Significant Wave Height Annual Average') title('Significant Wave Height SW England 1981-2010') show() If anybody knows how I could integrate these two plots I would be eternally grateful! Thanks, Jamie