python 2.7 - boxplot() being tripped up by set_yticks() format -
i trying make 2 boxplots on 1 figure, using plt.subplots()
. have done multiple times, making following result:
i had messed around scale , because plotting multiple sets of data range 0.0001 100, depending on dataframes being looped through graphing process, need have scale either in scientific format easy readability or in floats precision of 2 digits past decimal. solve this, produced following code:
import pandas pd import numpy np import matplotlib.pyplot plt mindex=pd.date_range('07/01/2012', periods=96, freq='h') data00=np.random.rand(96)*20 data01=np.random.rand(96)*0.01 data10=np.random.rand(96)*20 data11=np.random.rand(96)*0.01 df00=pd.dataframe({'observed': data00},index=mindex) df01=pd.dataframe({'observed': data01},index=mindex) df10=pd.dataframe({'wrf': data10},index=mindex) df11=pd.dataframe({'wrf': data11},index=mindex) df0list=[df00,df01] df1list=[df10,df11] k in xrange(len(df0list)): #graphing df0list[k]['hour']=pd.series(df0list[k].index.hour,index=df0list[k].index) df1list[k]['hour']=pd.series(df1list[k].index.hour,index=df1list[k].index) if df0list[k]['observed'].max() >= df1list[k]['wrf'].max(): ymax=df0list[k]['observed'].max() else: ymax=df1list[k]['wrf'].max() if df0list[k]['observed'].min() <= df1list[k]['wrf'].min(): ymin=df0list[k]['observed'].min() else: ymin=df1list[k]['wrf'].min() yscale=np.arange(ymin-ymin*0.1,ymax+ymax*0.005,((ymax+ymax*0.005)-(ymin-ymin*0.1))/10.) if ymin > 0.01: ybounds=['{:.2f}'.format(i) in yscale] else: ybounds=['{:.2e}'.format(i) in yscale] fig,axes=plt.subplots(ncols=1,nrows=2, figsize=(28,20)) df0list[k].boxplot(ax=axes[0],by='hour', whis= [10, 90], sym='') axes[0].set_yticks(ybounds) df1list[k].boxplot(ax=axes[1],by='hour', whis= [.10, .90], sym='') axes[1].set_yticks(ybounds) plt.show()
this produced graphs display top graph bounds not fitting. not sure how matplotlib handles displaying formats , thought making set_yticks()
function take in pre-formatted numpy array display in whatever array formatted. however, graph not save giving me typeerror: cannot perform reduce flexible type
. need format differently?
Comments
Post a Comment