def plot_depth(self, figname=None, show=False, imshow=False): """ plot the depth """ from matplotlib import pyplot as plt fig = plt.figure() ax = fig.add_subplot(1, 1, 1) depth = self.get_depths() mindep = depth.min() maxdep = depth.max() print("\nMin depth (m) = " + str(mindep)) print("Max depth (m) = " + str(maxdep) + "\n") if imshow: IM = ax.imshow(depth.transpose(), origin='lower') else: # need lon,lat qlon, qlat = self.get_corners() # make basemap for plotting import fns_plotting as Fplt bbox = [qlon.min(), qlat.min(), qlon.max(), qlat.max()] bmap = Fplt.start_map(bbox) IM = bmap.pcolor(qlon, qlat, depth, latlon=True, ax=ax, vmin=mindep, vmax=maxdep) Fplt.finish_map(bmap, do_fill=False) # colorbar cbar = fig.colorbar(IM) cbar.set_label("Depth, m", rotation=270, labelpad=20, fontsize=16) if figname is not None: print("\nSaving " + figname + "\n") fig.savefig(figname) else: show = True if show: plt.show(fig) ax.cla() plt.close(fig) return
def plot_field(grid, field, bmap): from matplotlib import pyplot # get corners - better for pcolor plots lon = grid.get_coords(0, ESMF.StaggerLoc.CORNER) lat = grid.get_coords(1, ESMF.StaggerLoc.CORNER) # data V = field.data[:, :] #plot pobj = FP.plot_object() PC = bmap.pcolor(lon, lat, V, latlon=True, ax=pobj.ax) pobj.fig.colorbar(PC) FP.finish_map(bmap) plt.show(pobj.fig) return pobj
lstil = ['-', '--'] for Poly in Polys: x, y = np.array(Poly.xy_coords).transpose() shp = SHgeom.Polygon(Poly.xy_coords) if shp.is_valid: bmap.plot(x, y, 'k', linewidth=2, ax=ax1) else: bmap.plot(x, y, 'c', linewidth=2, ax=ax1) # MIZ line x, y = np.array(Lino_ref.xy_coords).transpose() bmap.plot(x, y, linestyle=lstil[Lino_ref.func_val], ax=ax1) bmap.plot(x[:1], y[:1], 'v', ax=ax1) # 1st point # ice edges for Lino in Linos: x, y = np.array(Lino.xy_coords).transpose() bmap.plot(x, y, linestyle=lstil[Lino.func_val], ax=ax1) bmap.plot(x[:1], y[:1], '^', ax=ax1) # 1st point Fplt.finish_map(bmap, ax=ax1) if show: plt.show(fig) else: figname = figdir + '/' + cdate + "_polys.png" print('>' + figname) fig.savefig(figname) ax1.cla() plt.close(fig)
for vbl in ['depth','landmask']: if vbl=='depth': PC = bmap.pcolor(qlon,qlat,depth,latlon=True,ax=po.ax) cols = ['b'] else: PC = bmap.pcolor(qlon,qlat,landmask,latlon=True,ax=po.ax) cols = ['c'] cb = po.fig.colorbar(mappable=PC,cax=cax) # plot original selection vertices.append(vertices[0]) vlon,vlat = np.array(vertices).transpose() bmap.plot(vlon,vlat,'m',linewidth=4,ax=po.ax,latlon=True) if 0: # finish with coast etc Fplt.finish_map(bmap,ax=po.ax) # depth=0 contour bmap.contour(plon,plat,depth,colors=cols,linewidth=4,latlon=True,ax=po.ax,levels=[0.]) # save fig figname = outdir+"/test_"+gridname+"_"+vbl+".png" print('\nSaving '+figname+'\n') po.fig.savefig(figname) po.ax.cla() plt.close(po.fig)
else: # plot binary bm.pcolor(plon, plat, B, vmin=0., vmax=1., latlon=True) bm.colorbar() Nconts = len(contours) if Nconts > 0: print('number of contours: ' + str(Nconts) + '...\n') for n, contour in enumerate(contours): # print('contour: '+str(n)) # print('number of points: '+str(len(contour))+'\n') ivec = np.array(contour[:, 0], dtype=int) jvec = np.array(contour[:, 1], dtype=int) bm.plot(plon[ivec, jvec], plat[ivec, jvec], Ccol, linewidth=1.5, latlon=True) plt.title(vbl) Mplt.finish_map(bm) if 0: plt.show() else: figname = 'out/TP4test_' + vbl + '.png' print('\nsaving to ' + figname + '...\n') plt.savefig(figname) plt.close() fig.clf()
np.savez(outdir+'/thickness_anomaly_'+cdate1+'.npz',lon=olon,lat=olat,\ anomaly=hdiff.data,mask=hdiff.mask) print('\n-------------------') print('RMSE (m) = '+str(RMSEe)) print('Bias (m) = '+str(BIASe)) print('-------------------\n') # mask water for plotting hdiff.mask = np.logical_not(either_ice) if 0: print('Plotting weekly average') PC = bmap.pcolor(mlon,mlat,hav_m,ax=po.ax,vmin=0,vmax=hmax,latlon=True) if DOCB: po.fig.colorbar(PC) FP.finish_map(bmap,ax=po.ax) # po.ax.set_title('Mod') elif 0: print('Plotting weekly average - interpolated') PC = bmap.pcolor(olon,olat,hav_m2,ax=po.ax,vmin=0,vmax=hmax,latlon=True) if DOCB: po.fig.colorbar(PC) FP.finish_map(bmap,ax=po.ax) figname = figname.replace('.png','_interp.png') else: print('Plotting weekly average - anomaly') PC = bmap.pcolor(olon,olat,hdiff,ax=po.ax,latlon=True,vmin=-1.5,vmax=1.5) # if DOCB: cbar = po.fig.colorbar(PC) cbar.set_label('Thickness anomaly, m',rotation=270,labelpad=20,fontsize=16)