def timeseriesa(data, cdata, variable, ncdf, cncdf): #construct strings label = labels[variable] if variable in names: title = names[variable] else: title = variable subtitle = ncdf.filetitle + ' - ' + cncdf.filetitle filename = (variable + '_' + filenames[ncdf.filename] + '_tsa_' + filenames[cncdf.filename] + '.eps') #create plot x = calc.getx(ncdf) y = calc.anomalize(data, cdata, ncdf, cncdf) lp = plt.plot(x, y, 'k') plt.xlim(x[0], x[-1]) #label & title plt.xlabel('Years after eruption') plt.ylabel(label) ax.yaxis.ticklabel_format(style='sci', axis='y', scilimits=(-2,2)) ax.yaxis.locator_params(nbins=3, axis='y') #additional formatting ax = plt.gca() plt.rc('font', **font) plt.title(subtitle) ax.spines['bottom'].set_position('zero') ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') plt.savefig(filename) plt.close()
def __timeseriesa(data, cdata, variable, ncdf, cncdf, ax): #construct strings label = labels[variable] #format data data = ncdf.formatdata(data, 'timeseries', cncdf) cdata = ncdf.formatdata(cdata, 'timeseries') #create plot x = calc.getx(ncdf) y = calc.anomalize(data, cdata, ncdf, cncdf) lp = plt.plot(x, y, 'k') plt.xlim(x[0], x[-1]) #label & title plt.xlabel('Years after eruption') plt.ylabel(label) #additional formatting ax = plt.gca() ax.yaxis.set_major_locator(ticker.MaxNLocator(nbins=5)) ax.ticklabel_format(axis='y', style='sci', scilimits=(-1,1)) ax.spines['bottom'].set_position('zero') ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') return ax
def __prvtimea(data, cdata, variable, ncdf, cncdf, ax): #format data data = ncdf.formatdata(data, 'prvtime', cncdf) cdata = ncdf.formatdata(cdata, 'prvtime') #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), ple 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', color=None, cmap=cmap, vmin=datamin, vmax=datamax) plt.yscale('log') plt.xlim(x[0], x[-1]) plt.ylim(.1, 200) #create cbar 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('Pressure (hPa)') #additional formatting ax = plt.gca() ax.invert_yaxis() #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) #show/save plot return ax
def __prvtime(data, variable, ncdf, cncdf, ax): #construct strings label = labels[variable] #format data data = ncdf.formatdata(data, 'prvtime', cncdf) #calculate params x, y = calc.getx(ncdf), ple 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.yscale('log') plt.xlim(x[0], x[-1]) plt.ylim(.1, 200) #create cbar 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('Pressure (hPa)') #additional formatting ax = plt.gca() ax.invert_yaxis() #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 prvtimea(data, cdata, variable, ncdf, controlncdf): fig = plt.figure(figsize=figsize) ax = fig.add_subplot(111) fig.subplots_adjust(left=.2) #anomaly data = calc.anomalize(data, cdata, ncdf, controlncdf) #construct strings label = labels[variable] if variable in names: title = names[variable] else: title = variable if variable in variablefilenames: variabletitle = variablefilenames[variable] else: variabletitle = variable filename = (variabletitle + '_' + filenames[ncdf.filename] + '_pvta_' + filenames[controlncdf.filename] + '.eps') #colormap cmap = LinearSegmentedColormap('bwr', colors) #calculate params x, y = calc.getx(ncdf), ple z = data.transpose() datamax, datamin = 0, 0 if ((filenames[ncdf.filename] != 'q150') or (filenames[controlncdf.filename] != 'q0')): try: datamax = minmax[variable + 'a'][1] datamin = minmax[variable + 'a'][0] except KeyError: datamax, datamin = calc.getmax(data, True), calc.getmin(data, True) except Error: print Error else: try: datamax = minmax[variable + 'aa'][1] datamin = minmax[variable + 'aa'][0] except KeyError: datamax, datamin = calc.getmax(data, True), calc.getmin(data, True) except Error: print Error v = np.linspace(datamin, datamax, 17) #create plot cp = ax.contourf(x, y, z, v, extend='both', color=None, cmap=cmap, vmin=datamin, vmax=datamax) plt.yscale('log') plt.xlim(x[0], x[-1]) plt.ylim(.1, 200) #create cbar cbar = None ticks = np.linspace(datamin, datamax, 5, endpoint=True) format = ScalarFormatter() format.set_powerlimits((-2,2)) cbar = plt.colorbar(cp, orientation='horizontal', aspect=15, ticks=ticks, format=format, pad = .2) cbar.ax.set_xlabel(label) #label & title plt.xlabel('Years after eruption') plt.ylabel('Pressure (hPa)') #additional formatting ax = plt.gca() ax.invert_yaxis() plt.rc('font', **font) plt.title(title) #show/save plot plt.rc({'figure.autolayout': True}) #show/save plot ax.get_xaxis().majorTicks[-1].label1.set_horizontalalignment('right') ax.get_yaxis().majorTicks[0].label1.set_verticalalignment('top') plt.savefig(filename) plt.close()
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()
def prvtime(data, variable, ncdf, regionmin=None, regionmax=None): #construct figure object fig = plt.figure(figsize=figsize) ax = fig.add_subplot(111) fig.subplots_adjust(left=.2) #construct strings label = labels[variable] if variable in names: title = names[variable] else: title = variable if variable in variablefilenames: variabletitle = variablefilenames[variable] else: variabletitle = variable if regionmin != None and regionmax != None: if regionmin < 0: regionminstr = str(regionmin)[1:] + 'S' else: regionminstr = str(regionmin) + 'N' if regionmax < 0: regionmaxstr = str(regionmax)[1:] + 'S' else: regionmaxstr = str(regionmax) + 'N' variabletitle = regionminstr + '-' + regionmaxstr + '_' + variabletitle filename = variabletitle + '_' + filenames[ncdf.filename] + '_pvt' + '.eps' #calculate params x, y = calc.getx(ncdf), ple z = data.transpose() datamax, datamin = 0,0 try: datamax = minmax[variable][1] datamin = minmax[variable][0] except KeyError: datamax, datamin = calc.getmax(data), calc.getmin(data) except Error: print Error v = np.linspace(datamin, datamax, 17) norm = Normalize(vmin=datamin, vmax=datamax) #construct colormap #for info on how this works: #http://matplotlib.org/examples/pylab_examples/custom_cmap.html 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 cp = ax.contourf(x, y, z, v, extend='max', norm=norm, vmin=datamin, vmax=datamax, cmap=cmap) #fix x,y axes plt.yscale('log') plt.xlim(x[0], x[-1]) plt.ylim(.1, 200) #create cbar cbar = None ticks = np.linspace(float(datamin), float(datamax), 5, endpoint=True) format = ScalarFormatter() #set power limits, any e^+-x will be scientific notation format.set_powerlimits((-2,2)) cbar = plt.colorbar(cp, norm=norm, orientation='horizontal', aspect=15, extend='max', ticks = ticks, format=format, pad = .2) cbar.ax.set_xlabel(label) #label & title plt.xlabel('Years after eruption') plt.ylabel('Pressure (hPa)') #additional formatting ax = plt.gca() #invert pressure axis ax.invert_yaxis() #bring in last labels ax.get_xaxis().majorTicks[-1].label1.set_horizontalalignment('right') ax.get_yaxis().majorTicks[0].label1.set_verticalalignment('top') #fix font plt.rc('font', **font) #add title plt.title(title) #show/save plot plt.savefig(filename, format='eps') plt.close()