#path = '/home/laurent/.fonts/OSX_conv_LinuX/HelveticaNeue.ttf' #prop = font_manager.FontProperties(fname=path) #prop.set_weight = 'light' #mpl.rcParams['font.family'] = prop.get_name() #mpl.rcParams['font.weight'] = 'light' #cfont_clb = { 'fontweight':'ultra-light', 'fontsize':int(13*font_corr), 'color':'white' } #cfont_title = { 'fontname':'Ubuntu Mono', 'fontweight':'normal', 'fontsize':int(18*font_corr), 'color':'white' } #cfont_mail = { 'fontname':'Times New Roman', 'fontweight':'normal', 'fontstyle':'italic', 'fontsize':int(10*font_corr), 'color':'0.5'} # Colormaps for fields: pal_fld = bcm.chose_colmap(cpal_fld, log_ctrl=log_ctrl) norm_fld = colors.Normalize(vmin = tmin, vmax = tmax, clip = False) vc_fld = nmp.arange(tmin, tmax + dtemp, dtemp) #pal_ice = bcm.chose_colmap(cpal_ice) #norm_ice = colors.Normalize(vmin = rmin_ice, vmax = 1, clip = False) #pal_mm = bcm.chose_colmap('blk') #norm_mm = colors.Normalize(vmin = 0., vmax = 1., clip = False) print ''
def plot_nproj_extra(czone, rmin, rmax, dc, xlon, xlat, XF, XI, cfignm='fig', lkcont=False, cpal='jet', cbunit=' ', cfig_type='pdf', ctitle=' ', lforce_lim=False, cb_orient='vertical', i_cb_subsamp=1, dpi_fig=140, xlon_o=[0.], xlat_o=[0.], XI_o=[0.], rice_crit=0.15): # Plot projection with basemap... #=================================================================================== # INPUT: # xlon and xlat can be 1D or 2D !!! # #=================================================================================== from mpl_toolkits.basemap import Basemap from mpl_toolkits.basemap import shiftgrid import barakuda_colmap font_ttl, font_ylb, font_clb = __font_unity__() # For projections : vp = __give_proj__(czone) # projection information l_ice_obs = False if len(nmp.shape(XI_o)) > 1: l_ice_obs = True # must work with XFtmp rather than XF, because sometimes XF is overwrited... [ny, nx] = nmp.shape(XF) XFtmp = nmp.zeros(ny * nx) XFtmp.shape = [ny, nx] XFtmp[:, :] = XF[:, :] XItmp = nmp.zeros(ny * nx) XItmp.shape = [ny, nx] XItmp[:, :] = XI[:, :] if l_ice_obs: [ny2, nx2] = nmp.shape(XI_o) XIotmp = nmp.zeros(ny2 * nx2) XIotmp.shape = [ny2, nx2] XIotmp[:, :] = XI_o[:, :] if len(nmp.shape(xlat)) == 1 and len(nmp.shape(xlon)) == 1: #if czone == 'kav7' and xlon[0] >= 0.: # # Shifting data and longitude to be consistent with map projection # XItmp, xlon = shiftgrid(180.+xlon[0], XItmp, xlon, start=False, cyclic=360.0) # XFtmp, xlon = shiftgrid(180.+xlon[0], XFtmp, xlon, start=False, cyclic=360.0) LON_2D, LAT_2D = nmp.meshgrid(xlon, xlat) else: LAT_2D = nmp.zeros(ny * nx) LAT_2D.shape = [ny, nx] LAT_2D[:, :] = xlat[:, :] LON_2D = nmp.zeros(ny * nx) LON_2D.shape = [ny, nx] LON_2D[:, :] = xlon[:, :] if lforce_lim: __force_min_and_max__(rmin, rmax, XFtmp) vc = __vcontour__(rmin, rmax, dc) vci = __vcontour__(0., 1., 0.1) # Colorbar position/size if horizontal vcbar = [0.1, 0.08, 0.86, 0.03] # Figure/canvas size: if cb_orient == 'horizontal': if czone == 'natarct': vfig_size = [5.8, 5.6] vsporg = [0.08, 0.1, 0.9, 0.92] vcbar = [0.05, 0.08, 0.9, 0.03] if czone == 'npol2': vfig_size = [4.4, 5.6] vsporg = [0.01, 0.15, 1., 0.8] vcbar = [0.05, 0.065, 0.92, 0.03] if czone == 'kav7': vfig_size = [8.1, 5.6] vsporg = [0.001, 0.15, 1., 0.8] vcbar = [0.04, 0.08, 0.92, 0.03] else: # Vertical color bar on the rhs vfig_size = [7., 7.] vsporg = [0.1, 0.1, 0.85, 0.85] if czone == 'nseas': vfig_size = [7., 5.4] vsporg = [0.085, 0.03, 0.9, 0.94] if czone == 'natarct': vfig_size = [7.7, 7.] vsporg = [0.07, 0.033, 0.92, 0.93] if czone == 'spstere': vfig_size = [7., 5.8] vsporg = [0.075, 0.035, 0.93, 0.93] if czone == 'npol2': vfig_size = [7., 7.1] vsporg = [0.085, 0.03, 0.91, 0.94] #if czone == 'kav7': vfig_size = [ 7., 5. ]; vsporg = [0.085, 0.03, 0.91, 0.94] fig = plt.figure(num=1, figsize=(vfig_size), dpi=None, facecolor='w', edgecolor='k') ax = plt.axes(vsporg, axisbg='w') ## Colmap: colmap = barakuda_colmap.chose_colmap(cpal) pal_norm = colors.Normalize(vmin=rmin, vmax=rmax, clip=False) mpl.rcParams['contour.negative_linestyle'] = 'solid' plt.contour.negative_linestyle = 'solid' colmapi = barakuda_colmap.chose_colmap('blanc') #pal_normi = colors.Normalize(vmin = 0., vmax = 1., clip = True) if vp[1] == 'lcc' or vp[1] == 'cyl': carte = Basemap(llcrnrlon=vp[2],llcrnrlat=vp[3],urcrnrlon=vp[4],urcrnrlat=vp[5],\ resolution=vp[9],area_thresh=1000.,projection=vp[1],\ lat_1=vp[6],lon_0=vp[7]) elif vp[1] == 'stere': if vp[0] == 'spstere' or vp[0] == 'npstere': carte = Basemap(projection=vp[0], boundinglat=vp[6], lon_0=vp[7], resolution=vp[9]) else: carte = Basemap(llcrnrlon=vp[2],llcrnrlat=vp[3],urcrnrlon=vp[4],urcrnrlat=vp[5],\ resolution=vp[9],area_thresh=1000.,projection='stere',\ lat_0=vp[6],lon_0=vp[7]) elif vp[1] == 'kav': print ' *** plot_nproj.barakuda_plot => Projection ' + vp[ 0] + ' / ' + str(vp[7]) + ' / ' + vp[9] carte = Basemap(projection=vp[0], lon_0=vp[7], resolution=vp[9]) else: print 'ERROR: barakuda_plot.py => proj type ' + vp[1] + ' unknown!!!' sys.exit(0) x0, y0 = carte(LON_2D, LAT_2D) if l_ice_obs: x2, y2 = carte(xlon_o, xlat_o) cf = carte.contourf(x0, y0, XFtmp, vc, cmap=colmap, norm=pal_norm) # Black contours if needed : if lkcont: ckf = carte.contour(x0, y0, XFtmp, vc, colors='k', linewidths=0.5) if cpal != 'ice': for c in cf.collections: c.set_zorder(0.5) # Changing zorder so black cont. on top for c in ckf.collections: c.set_zorder( 0.5) # of filled cont. and under continents (zorder 1) # Adding Sea-ice: cfi = carte.contourf(x0, y0, XItmp, [rice_crit, 1.], cmap=colmapi) cf2 = carte.contour(x0, y0, XItmp, [rice_crit], colors='k', linewidths=0.5) for c in cfi.collections: c.set_zorder(0.75) for c in cf2.collections: c.set_zorder(1) if l_ice_obs: cf3 = carte.contour(x2, y2, XIotmp, [rice_crit], colors='r', linewidths=2.) for c in cf3.collections: c.set_zorder(1) carte.drawcoastlines() carte.fillcontinents(color='grey') carte.drawmapboundary() if vp[1] == 'lcc' or vp[1] == 'cyl': carte.drawmeridians(nmp.arange(-360, 360, vp[8]), labels=[0, 0, 0, 1]) carte.drawparallels(nmp.arange(-90, 90, vp[8]), labels=[1, 0, 1, 0]) if vp[1] == 'stere': carte.drawmeridians(nmp.arange(-180, 180, 20), labels=[0, 0, 0, 1]) carte.drawparallels(nmp.arange(-90, 90, 10), labels=[1, 0, 0, 0]) #plt.title(ctitle, **font_ttl) # ADDING COLORBAR # =============== if cb_orient == 'horizontal': clbax = fig.add_axes(vcbar) # axes for colorbar clb = plt.colorbar(cf, cax=clbax, ticks=vc, drawedges=lkcont, orientation='horizontal') for t in clb.ax.get_xticklabels(): t.set_font.size(10) else: clb = plt.colorbar(cf, ticks=vc, drawedges=lkcont) for t in clb.ax.get_yticklabels(): t.set_fontsize(16) if i_cb_subsamp > 1: cn_clb = [] jcpt = 0 for rtck in vc: if jcpt % i_cb_subsamp == 0: if float(int(rtck)) == round(rtck, 0): cn_clb.append(str(int(rtck))) # we can drop the ".0" else: cn_clb.append(str(rtck)) # keeping the decimals... else: cn_clb.append(' ') jcpt = jcpt + 1 clb.ax.set_xticklabels(cn_clb) clb.set_label('(' + cbunit + ')', **font_clb) font_lab = {'fontname': 'Arial', 'fontweight': 'normal', 'fontsize': 24} ax.annotate(ctitle, xy=(0.4, 0.95), xycoords='axes fraction', **font_lab) plt.savefig(cfignm + '.' + cfig_type, dpi=dpi_fig, orientation='portrait', transparent=True) #, transparent=True, acecolor='w', edgecolor='w', plt.close(1) del LON_2D, LAT_2D, XFtmp return
cfont_mail = { 'fontname': 'Times New Roman', 'fontweight': 'normal', 'fontstyle': 'italic', 'fontsize': int(14. * font_rat), 'color': '0.8' } cfont_titl = { 'fontname': 'Helvetica Neue', 'fontweight': 'light', 'fontsize': int(30. * font_rat), 'color': 'w' } # Colormaps for fields: pal_fld = bcm.chose_colmap(cpal_fld) if l_log_field: norm_fld = colors.LogNorm(vmin=tmin, vmax=tmax, clip=False) if l_pow_field: norm_fld = colors.PowerNorm(gamma=pow_field, vmin=tmin, vmax=tmax, clip=False) else: norm_fld = colors.Normalize(vmin=tmin, vmax=tmax, clip=False) if l_show_lsm: pal_lsm = bcm.chose_colmap('land_dark') norm_lsm = colors.Normalize(vmin=0., vmax=1., clip=False) if l_do_ice:
params = { 'font.family':'Ubuntu', 'font.size': int(12), 'legend.fontsize': int(12), 'xtick.labelsize': int(12), 'ytick.labelsize': int(12), 'axes.labelsize': int(12) } mpl.rcParams.update(params) cfont_clb = { 'fontname':'Arial', 'fontweight':'normal', 'fontsize':13, 'color':'white' } cfont_title = { 'fontname':'Ubuntu Mono', 'fontweight':'normal', 'fontsize':18, 'color':'white' } cfont_mail = { 'fontname':'Times New Roman', 'fontweight':'normal', 'fontstyle':'italic', 'fontsize':10, 'color':'0.5'} # Colormaps for fields: pal_fld = bcm.chose_colmap(cpal_fld) norm_fld = colors.Normalize(vmin = tmin, vmax = tmax, clip = False) #pal_ice = bcm.chose_colmap(cpal_ice) #norm_ice = colors.Normalize(vmin = rmin_ice, vmax = 1, clip = False) pal_lsm = bcm.chose_colmap('blk') norm_lsm = colors.Normalize(vmin = 0., vmax = 1., clip = False) vc_fld = nmp.arange(tmin, tmax + dtemp, dtemp) print '' rh = 7.5 jrot = -1 + jt0*nsts
cpal_fld = sys.argv[1] tmin = float(sys.argv[2]) tmax = float(sys.argv[3]) rdt = float(sys.argv[4]) vc_fld = nmp.arange(tmin, tmax + rdt, rdt) #for cpal_fld in bcm.list_cmap_barakuda : for cpal_fld in [cpal_fld]: cpal_fld = cpal_fld cfig = 'show_colmap_' + cpal_fld + '.png' pal_fld = bcm.chose_colmap(cpal_fld) nrm_fld = mplc.Normalize(vmin=tmin, vmax=tmax, clip=False) fig = plt.figure(num=1, figsize=(10, 2), dpi=None, facecolor='w', edgecolor='k') ax = plt.axes([0.01, 0.12, 0.98, 0.8]) clb = mpl.colorbar.ColorbarBase(ax, ticks=vc_fld, cmap=pal_fld, norm=nrm_fld,