def __latvtimea(data, cdata, variable, ncdf, cncdf, ax): #format data data = ncdf.formatdata(data, 'latvtime', cncdf) cdata = ncdf.formatdata(cdata, 'latvtime') #anomaly data = calc.anomalize(data, cdata, ncdf, cncdf) #construct strings label = labels[variable] #colormap cmap = LinearSegmentedColormap('bwr', colors) #calculate params x, y = calc.getx(ncdf), calc.gety(ncdf) z = data.transpose() datamax, datamin = calc.getmax(data, True), calc.getmin(data, True) v = np.linspace(datamin, datamax, 41) #create plot cp = plt.contourf(x, y, z, v, extend='both', colors=None, cmap=cmap, vmin=datamin, vmax=datamax) plt.xlim(x[0], x[-1]) plt.ylim(-90, 90) #create colorbar ticks = np.linspace(datamin, datamax, 3) cbar = plt.colorbar(cp, orientation='horizontal', extend='both', aspect=40, ticks=ticks, format='%.2g') cbar.ax.set_xlabel(label) #label & title plt.xlabel('Years after eruption') plt.ylabel('Degrees latitude') #add control stats cmean = stats.nanmean(cdata.flat) cstd = stats.nanstd(cdata.flat) string = ('Control mean: ' + '%.2g'%cmean + '\nControl standard deviation: ' + '%.2g'%cstd) plt.figtext(.02,.02,string, fontsize=12) #additional formating ax = plt.gca() plt.yticks(np.linspace(-90, 90, 7, endpoint=True)) #show/save plot return ax
def __latvtime(data, variable, ncdf, cncdf, ax): #construct strings label = labels[variable] #format data data = ncdf.formatdata(data, 'latvtime', cncdf) #calculate params x, y = calc.getx(ncdf), calc.gety(ncdf) z = data.transpose() datamax, datamin = calc.getmax(data), calc.getmin(data) v = np.linspace(datamin, datamax, 41) cmap = LinearSegmentedColormap('red', colors2) #create plot cp = plt.contourf(x, y, z, v, extend='both', vmin=datamin, vmax=datamax, cmap=cmap) plt.xlim(x[0], x[-1]) plt.ylim(-90, 90) #create colorbar ticks = np.linspace(datamin, datamax, 3) cbar = plt.colorbar(cp, orientation='horizontal', extend='both', aspect=40, ticks=ticks) cbar.ax.set_xlabel(label) #label & title plt.xlabel('Years after eruption') plt.ylabel('Degrees latitude') #additional formating ax = plt.gca() plt.yticks(np.linspace(-90, 90, 7, endpoint=True)) #show/save plot return ax
def latvtimegiss(data, variable, ncdf): plt.figure(figsize=figsize) #construct strings label = labels[variable] if variable in names: title = names[variable] else: title = variable subtitle = ncdf.filetitle filename = variable + '_' + filenames[ncdf.filename] + '_lvt' + '.eps' #calculate params x, y = calc.getx(ncdf), calc.gety(ncdf) z = data.transpose() datamax, datamin = calc.getmax(data), calc.getmin(data) v = np.linspace(datamin, datamax, 17) #colormap #cmap = plt.get_cmap('jet') #cmap.set_under(color='w') cdict = matplotlib.cm.get_cmap('jet')._segmentdata if cdict['red'][1]!=(0.05,1,1): cdict['red'] = list(cdict['red']) cdict['red'][0]=(0,1,1) cdict['red'].insert(1, (0.05,1,1)) cdict['red'] = tuple(cdict['red']) cdict['blue'] = list(cdict['blue']) cdict['blue'][0]=(0,1,1) cdict['blue'].insert(1, (0.05,1,1)) cdict['blue'] = tuple(cdict['blue']) cdict['green'] = list(cdict['green']) cdict['green'][0]=(0,1,1) cdict['green'].insert(1, (0.05,1,1)) cdict['green'] = tuple(cdict['green']) cmap = LinearSegmentedColormap('jet2', cdict) #create plot extend = '' if datamin == 0: extend='max' else: extend='both' norm = Normalize(vmin=datamin, vmax=datamax, clip=False) cp = plt.contourf(x, y, z, v, extend=extend, vmin=datamin, vmax=datamax, cmap=cmap, origin='lower', norm=norm) plt.xlim(x[0], x[-1]) plt.ylim(-90, 90) #create colorbar cbar = plt.colorbar(cp, orientation='horizontal', aspect=15, format='%.2g', pad=0.2) cbar.ax.set_xlabel(label) #label & title plt.xlabel('Years after eruption') plt.ylabel('Latitude') '''for label in cbar.ax.xaxis.get_ticklabels()[1::2]: label.set_visible(False)''' newlabels=[] for label in cbar.ax.xaxis.get_ticklabels()[::2]: newlabels.append(label.get_text()) cbar.ax.xaxis.set_ticklabels(newlabels) newticks=[] for tick in cbar.ax.get_xticks()[::2]: newticks.append(tick) cbar.ax.set_xticks(newticks) #additional formating ax = plt.gca() plt.yticks(np.linspace(-90, 90, 7, endpoint=True)) ax.get_xaxis().majorTicks[-1].label1.set_horizontalalignment('right') ax.get_yaxis().majorTicks[-1].label1.set_verticalalignment('top') plt.rc('font', **font) plt.title(title) #show/save plot plt.savefig(filename, bbox_inches='tight') #print str(max(z.flat)) + " + " + str(min(z.flat)) plt.close()
def latvtimea(data, cdata, variable, ncdf, controlncdf): #anomaly plt.figure(figsize=figsize) data = calc.anomalize(data, cdata, ncdf, controlncdf) #construct strings label = labels[variable] if variable in names: title = names[variable] else: title = variable subtitle = title filename = (variable + '_' + filenames[ncdf.filename] + '_lvta_' + filenames[controlncdf.filename] + '.eps') #colormap cmap = LinearSegmentedColormap('bwr', colors) #calculate params x, y = calc.getx(ncdf), calc.gety(ncdf) z = data.transpose() datamax, datamin = calc.getmax(data, True), calc.getmin(data, True) v = np.linspace(datamin, datamax, 17) #create plot cp = plt.contourf(x, y, z, v, extend='both', colors=None, cmap=cmap, vmin=datamin, vmax=datamax) plt.xlim(x[0], x[-1]) plt.ylim(-90, 90) #create colorbar cbar = plt.colorbar(cp, orientation='horizontal', aspect=15, format="%.2g", pad = .2) cbar.ax.set_xlabel(label) #label & title plt.xlabel('Years after eruption') plt.ylabel('Latitude') #add control stats '''cmean = stats.nanmean(cdata.flat) #cmean = calc.anlmean(cdata) cstd = stats.nanstd(cdata.flat) #cstd = calc.anlstd(cdata) string = ('Control mean: ' + '%.2g'%cmean + '\nControl standard deviation: ' + '%.2g'%cstd) plt.figtext(.02,.02,string, fontsize=12)''' newlabels=[] for label in cbar.ax.xaxis.get_ticklabels()[::2]: newlabels.append(label.get_text()) cbar.ax.xaxis.set_ticklabels(newlabels) newticks=[] for tick in cbar.ax.get_xticks()[::2]: newticks.append(tick) cbar.ax.set_xticks(newticks) #additional formating ax = plt.gca() ax.get_xaxis().majorTicks[-1].label1.set_horizontalalignment('right') plt.yticks(np.linspace(-90, 90, 7, endpoint=True)) ax.get_yaxis().majorTicks[-1].label1.set_verticalalignment('top') plt.rc('font', **font) plt.title(subtitle) #show/save plot plt.savefig(filename, bbox_inches='tight') plt.close()