def plot_ts(pds_set, pds_dif, colors, labels, lims, fname): # --- Build Map --- plt.figure(figsize=(10, 7)) plt.rc('font', family='serif') font_size = 12 mpl.rcParams.update({'font.size': font_size}) # --- panel 1 axes = plt.gca() for j in range(0, len(pds_set)): df1 = pds_set[j] df1.plot(color=colors[j], ls='-', label=labels[j]) plt.grid() plt.ylabel('xCO, $molec \cdot cm^{-2}$') plt.xlabel('') plt.ylim(lims[0]) #axes.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m")) #axes.set_xlim(['20141231 00:00:00', '20151231 00:00:00']) plt.legend(loc="upper left", ncol=9, prop={'size': font_size - 3}, fancybox=True, shadow=True) # --- save a_saveplot.save_plot(fname, ext="png", close=True, verbose=False)
def plot_test_map(self, var1d, lats, lons, pname, cdate, title=False): # --- Build Map --- fig = plt.figure() plt.rc('font', family='serif') my_cmap = plt.get_cmap('jet') font_size = 10 # --- limits map_lims = self.map_lims # --- map labels --- mp = Basemap(llcrnrlat=map_lims[0], urcrnrlat=map_lims[1], llcrnrlon=map_lims[2], urcrnrlon=map_lims[3], projection='cyl', resolution='l') mp.drawcoastlines(color='grey') mp.drawcountries(color='grey') mp.drawparallels(np.arange(-90, 91, map_lims[4]), labels=[True, False, True, False], fontsize=font_size, color='grey') mp.drawmeridians(np.arange(0, 360, map_lims[5]), labels=[False, True, False, True], fontsize=font_size, color='grey') sc = mp.scatter(lons, lats, c=var1d, s=10, cmap=my_cmap, edgecolors=None, linewidth=0) cb = mp.colorbar() # --- title if title: plt.title(title + ' for ' + cdate) # --- save to plot a_saveplot.save_plot(pname, ext="png", close=True, verbose=False) plt.show()
def plot_map_sc(var1d, lats, lons, map_lims, var_lims, plot_name, title, map_marks): # --- Build Map --- fig = plt.figure() plt.rc('font', family='serif') my_cmap = plt.get_cmap('jet') font_size = 12 # --- map labels --- mp = Basemap(projection='cyl', llcrnrlat=map_lims[0], urcrnrlat=map_lims[1], llcrnrlon=map_lims[2], urcrnrlon=map_lims[3], resolution='l') mp.drawcoastlines(color='grey') mp.drawcountries(color='grey') mp.drawparallels(np.arange(-90, 91, map_lims[4]), labels=[True, False, True, False], fontsize=font_size, color='grey') mp.drawmeridians(np.arange(0, 360, map_lims[5]), labels=[False, True, False, True], fontsize=font_size, color='grey') x, y = mp(lons, lats) sc2 = mp.scatter(x, y, c=var1d, s=13, marker='s', cmap=my_cmap) plt.clim(var_lims[0], var_lims[-1]) # --- title if title: plt.title(title, y=1.05, fontsize=font_size) # --- plot grid marks if map_marks != []: put_marks(mp, map_marks, font_size) # --- cbar axcbar = fig.add_axes([0.125, 0.14, 0.775, 0.03]) cbar = fig.colorbar(sc2, orientation='horizontal', ticks=var_lims, cax=axcbar) cbar.ax.tick_params(labelsize=font_size) cbar.update_ticks() # --- save to plot a_saveplot.save_plot(plot_name, ext="png", close=True, verbose=False) plt.show()
def plot_map_int(var2d, mask, lats, lons, map_lims, cbar_lims, plot_name, title, map_marks): # --- Build Map --- fig = plt.figure() plt.rc('font', family='serif') my_cmap = plt.get_cmap('jet') font_size = 12 # --- map labels --- mp = Basemap(projection='cyl', llcrnrlat=map_lims[0], urcrnrlat=map_lims[1], llcrnrlon=map_lims[2], urcrnrlon=map_lims[3], resolution='l') mp.drawcoastlines(color='grey') mp.drawcountries(color='grey') mp.drawparallels(np.arange(-90, 91, map_lims[4]), labels=[True, False, True, False], fontsize=font_size, color='grey') mp.drawmeridians(np.arange(0, 360, map_lims[5]), labels=[False, True, False, True], fontsize=font_size, color='grey') # --- color bar min/max if cbar_lims == []: # --- min-max minn = np.nanmin(var2d) maxx = np.nanmax(var2d) print('Map min/max', minn, maxx) var2d[var2d > maxx] = maxx vp = np.linspace(minn, maxx, 100, endpoint=True) vc = np.linspace(minn, maxx, 11, endpoint=True) else: vp = np.linspace(cbar_lims[0], cbar_lims[1], 100, endpoint=True) vc = np.arange(cbar_lims[0], cbar_lims[1]*1.001, cbar_lims[2]) # --- map plot x, y = np.meshgrid(lons, lats) x, y = mp(x, y) import scipy.interpolate as interpolate vals = ~np.isnan(var2d) # --- interpolation f = interpolate.Rbf(x[vals], y[vals], var2d[vals], function='cubic') interpolated = f(x, y) + mask interpolated[interpolated < cbar_lims[0]] = cbar_lims[0] interpolated[interpolated > cbar_lims[1]] = cbar_lims[1] sc1 = mp.contourf(x, y, interpolated, vp, cmap=my_cmap) # --- title if title: plt.suptitle(title, y=1.05, fontsize=font_size) # --- plot grid marks if map_marks != []: put_marks(mp, map_marks, font_size) # --- cbar axcbar = fig.add_axes([0.125, 0.14, 0.775, 0.03]) cbar = fig.colorbar(sc1, orientation='horizontal', ticks=vc, cax=axcbar) cbar.ax.tick_params(labelsize=font_size) cbar.update_ticks() # --- save to plot a_saveplot.save_plot(plot_name, ext="png", close=True, verbose=False) plt.show()
def plot_map(self, var1d, lats, lons, sites, plot_name, title, yr): from matplotlib.font_manager import FontProperties fp = FontProperties(fname=r'C:\WINDOWS\Fonts\msgothic.ttc', size=5) # --- Build Map --- fig = plt.figure() plt.rc('font', family='serif') my_cmap = plt.get_cmap('rainbow') font_size = 10 # --- limits map_lims = self.map_lims # --- map labels --- mp = Basemap(projection='gall', llcrnrlat=map_lims[0], urcrnrlat=map_lims[1], llcrnrlon=map_lims[2], urcrnrlon=map_lims[3], resolution='l') mp.drawcoastlines(color='grey') mp.drawcountries(color='grey') mp.drawparallels(np.arange(-90, 91, map_lims[4]), labels=[True, False, True, False], fontsize=font_size, color='grey') mp.drawmeridians(np.arange(2, 362, map_lims[5]), labels=[False, True, False, True], fontsize=font_size, color='grey') x, y = mp(lons, lats) mp.scatter(x, y, c=var1d, s=10, cmap=my_cmap) # --- selected sites o_site = '' for j in range(0, len(sites), 1): n_lat = lats[j] n_lon = lons[j] n_site = sites[j] # --- plot only unploted sites # if n_site != o_site: if n_site[:1] != o_site[:1]: x, y = mp(n_lon, n_lat) plt.text(x, y, n_site, color='k', weight='bold', fontsize=font_size - 6, fontproperties=fp) o_site = sites[j] # --- title plt.title(title + ' for ' + yr) # --- legend # plt.legend(loc="lower left", ncol=4, prop={'size': font_size - 4}, fancybox=True, shadow=True) plt.colorbar() # --- save to plot a_saveplot.save_plot(plot_name, ext="png", close=True, verbose=False) plt.show()