def taylorGraph(y0, y1, y2, y3): """ Generate taylor diagram Parameters: ----------- y0 : reference dataset y1...y3 : aproximated dataset by models Returns: -------- taylor Graph plot """ data = y0 #CONAE #print data refstd = data.std(ddof=1) # Reference standard deviation # Models m1 = y1 # MLR m2 = y2 # MLP m3 = y3 # MARS # Compute stddev and correlation coefficient of models samples = np.array([ [m.std(ddof=1), np.corrcoef(data, m)[0,1]] for m in (m1, m2)]) #samples = np.array([ [sklearn.metrics.r2_score(data, m)**2, np.corrcoef(data, m)[0,1]] #for m in (m1,m2)]) #samples = np.array([ [statistics.RMSE(data,m), np.corrcoef(data, m)[0,1]] #for m in (m1,m2)]) #print "AQUI!!" + str(samples) fig = plt.figure(10, facecolor="white") #ax1 = fig.add_subplot(1,1,1, xlabel='X', ylabel='Y') # Taylor diagram dia = TaylorDiagram(refstd, fig=fig, rect=111, label="Conae") colors = plt.matplotlib.cm.jet(np.linspace(0,1,len(samples))) model = [ "MLR", "MLP", "MARS"] color = ["green", "blue", "red" ] markers = ["s", "o", "-"] # Add samples to Taylor diagram for i,(stddev,corrcoef) in enumerate(samples): dia.add_sample(stddev, corrcoef, marker=markers[i],markersize=7, ls='', c=color[i], label= str(model[i])) # Add RMS contours, and label them contours = dia.add_contours(colors='0.5') plt.clabel(contours, inline=1, fontsize=10) # Add a figure legend fig.legend(dia.samplePoints, [ p.get_label() for p in dia.samplePoints ], numpoints=1, prop=dict(size='small'), loc='upper right') plt.show()
def taylorplot(self, dpi=72): ''' Plots the Taylor diagram for this matchup. Args: - *dpi* (optional): the figure's DPI (default: 72). Returns: a matplotlib Figure object and a matplotlib Axes object ''' #Create the figure fig = plt.figure() fig.set_dpi(dpi) #Create the TaylorDiagram object dia = TaylorDiagram(self.Ref.std(), fig=fig, label="Reference") #Calculate the correlation coefficient corr = self.correlation() #Plot the model point dia.add_sample(self.Model.std(), corr, marker='s') # Add RMS contours, and label them contours = dia.add_contours(colors='0.5') plt.clabel(contours, inline=1, fontsize=10) return fig, dia.ax
def main(): server,dovalidation, station, startdate, enddate, obstyle, expname, oper,tickint = readConfig() vobsm = readObs(server,station, startdate, enddate,obstyle) if dovalidation["experiment"] :readExpr(expname,station,startdate,enddate,vobsm) if dovalidation["operational"] :readOper(server,oper,station,startdate,enddate,vobsm) stick = getDateRange(startdate,enddate) itick = range(len(stick)) iitick=itick[::tickint] fig=plt.figure(num=1,figsize=(12.0,6.0),dpi=300,facecolor='w',edgecolor='k') ax = fig.add_axes([0.08, 0.08, 0.8, 0.8], axisbg = '1.0') ax.set_xlabel('Time',fontsize='20',weight='bold') ax.set_ylabel ('SSH(m)',fontsize='20',weight='bold') for im in range(len(vssh)): if im == 0: ax.plot(vssh[im],'o-',color=ccolor[im],ms=2) else: ax.plot(vssh[im],linestyle=cstyle[im],color=ccolor[im],lw=0.75) print clegend print ccolor ax.legend(clegend, numpoints=1, prop=dict(size='small'),loc="best") ax.grid() ax.set_title(station,fontsize="30") ax.xaxis.set_ticks(itick[::tickint]) ax.set_xlim(iitick[0],iitick[-1]) ax.xaxis.set_ticklabels(stick[::tickint],rotation="vertical",fontsize="15") print "Creating figure for station", station, " ssh"+station+'.png' plt.savefig("ssh"+station+'.png', bbox_inches='tight',dpi=300,facecolor='w',edgecolor='w',orientation='portrait') plt.close(1) TaylorDiagram(RMSVEC=rms, RMSDVEC=rmsd, CORVEC=cor,COLORVEC=ccolor,LABELVEC=clegend, station=station, info=startdate+"-"+enddate)
rects = dict(monclim=121, interannual=122) legcol = dict(monclim=[0.4, 0.7], interannual=[0.9, 0.7]) fig = PLT.figure(figsize=(15, 8)) fig.suptitle("Mixed layer depth", size='x-large') #for season in ['winter','spring','summer','autumn']: id_df = 0 for intvl in ['monclim']: print(rects[intvl], stdrefs[intvl]) dia = TaylorDiagram(stdrefs[intvl], fig=fig, rect=rects[intvl], label='deBoyer et al. (2004)', srange=(0, 2.5)) #dia.ax.plot(x95,y95,color='k') #dia.ax.plot(x99,y99,color='k') # Add samples to Taylor diagram for mip in range(2): id_df = id_df + 1 i = 0 for index, row in mldstats[id_df - 1].iterrows(): print(row[0], row[1]) if (index != 'Reference'): stddev = row[1]
#print(index) #print(row[0],row[1]) if (index == 'Reference'): stdrefs['monclim'] = row[1] print(stdrefs) rects = dict(interannual=224, monclim=224) legcol = dict(interannual=[0.825, 0.05], monclim=[0.825, 0.05]) #legcol = dict(interannual=[1.00,0.26], # monclim=[1.00,0.26]) id_df = 0 dia = TaylorDiagram(stdrefs[intvl], fig=fig, rect=rects[intvl], label='PCMDI-SST') for mip in range(2): id_df = id_df + 1 i = 0 for index, row in sststats[id_df - 1].iterrows(): print(row[0], row[1]) if (index != 'Reference'): stddev = row[1] corrcoef = row[0] name = index + '-omip' + str(mip + 1) dia.add_sample( stddev, corrcoef, marker=markers[i],
if args.make_figures: # the lines below activate TaylorPlots but it is disabled for now fig = plt.figure(figsize=(11, 7)) #width,height i = 1 axes = {} axes_taylor = {} colors = ['r', 'g', 'b', 'm', 'y', 'purple', 'orange', 'sienna', 'navy'] symbols = ['*', 'x', '+'] dias = {} i = 1 for varkey in ['h', 'theta', 'q']: dias[varkey] = TaylorDiagram(1., srange=[0.0, 1.7], fig=fig, rect=(230 + i + 3), label='Reference') axes[varkey] = fig.add_subplot(2, 3, i) for ikey, key in enumerate(args.experiments.strip(' ').split(' ')[:1]): icolor = 0 for ikoeppen, koeppen in koeppenlookuptable.iterrows(): print(ikoeppen, ':', koeppen) kgc_select = ( c4gldata[key].frames['stats']['records_all_stations_ini'] ['KGCname'] == koeppen['KGCID']) koeppen_mod = c4gldata[key].frames['stats'][ 'records_all_stations_mod_stats']['d' + varkey + 'dt'][kgc_select]
#y99 = [0.0, 3.45] x95 = [0.05, 13.9] # For Prcp, this is for 95th level (r = 0.195) y95 = [0.0, 71.0] x99 = [0.05, 19.0] # For Prcp, this is for 99th level (r = 0.254) y99 = [0.0, 70.0] rects = dict(winter=221, spring=222, summer=223, autumn=224) fig = PLT.figure(figsize=(11, 8)) fig.suptitle("Precipitations", size='x-large') for season in ['winter', 'spring', 'summer', 'autumn']: dia = TaylorDiagram(stdrefs[season], fig=fig, rect=rects[season], label='Reference') dia.ax.plot(x95, y95, color='k') dia.ax.plot(x99, y99, color='k') # Add samples to Taylor diagram for i, (stddev, corrcoef, name) in enumerate(samples[season]): dia.add_sample( stddev, corrcoef, marker='$%d$' % (i + 1), ms=10, ls='', #mfc='k', mec='k', # B&W mfc=colors[i],
x95 = [0.05, 13.9] # For Prcp, this is for 95th level (r = 0.195) y95 = [0.0, 71.0] x99 = [0.05, 19.0] # For Prcp, this is for 99th level (r = 0.254) y99 = [0.0, 70.0] rects = dict(winter=221, spring=222, summer=223, autumn=224) fig = PLT.figure(figsize=(11,8)) fig.suptitle("Precipitations", size='x-large') for season in ['winter','spring','summer','autumn']: dia = TaylorDiagram(stdrefs[season], fig=fig, rect=rects[season], label='Reference') dia.ax.plot(x95,y95,color='k') dia.ax.plot(x99,y99,color='k') # Add samples to Taylor diagram for i,(stddev,corrcoef,name) in enumerate(samples[season]): dia.add_sample(stddev, corrcoef, marker='$%d$' % (i+1), ms=10, ls='', #mfc='k', mec='k', # B&W mfc=colors[i], mec=colors[i], # Colors label=name) # Add RMS contours, and label them contours = dia.add_contours(levels=5, colors='0.5') # 5 levels dia.ax.clabel(contours, inline=1, fontsize=10, fmt='%.1f')