def test_yaxis_labels_with_axes(self): import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.set_ylim(0, 3) iplt.pcolor(self.cube, axes=ax, coords=('bar', 'str_coord')) plt.close(fig) self.assertPointsTickLabels('yaxis', ax)
def pcolor(cube, *args, **kwargs): """ Draws a labelled pseudocolor plot based on the given Cube. See :func:`iris.plot.pcolor` for details of valid keyword arguments. """ coords = kwargs.get('coords') result = iplt.pcolor(cube, *args, **kwargs) _label_with_bounds(cube, result, coords=coords) return result
def hatch_cube(cube, axes=None, p=0.05, **kwArgs): pD = dict(hatch='.', zorder=9, alpha=0.) pD.update(kwArgs) if axes is None: axes = plt.gca() lo0, la0 = cube.coord('longitude'), cube.coord('latitude') cube_ = cube.copy(np.ma.masked_greater(cube.data, p)) if lo0.ndim == 1: pch = iplt.pcolor(cube_, axes=axes, **pD) else: if hasattr(lo0, 'has_bounds') and lo0.has_bounds(): x, y = lo0.contiguous_bounds(), la0.contiguous_bounds() else: x, y = _2d_bounds(lo0.points, la0.points) pch = axes.pcolor(x, y, cube_.data, transform=ccrs.PlateCarree(), **pD) return pch
def fishcell(self, levels=[ 0, 0.3, 1.6, 3.4, 5.5, 8., 10.8, 13.9, 17.2, 20.8, 24.5, 28.5, 32.7 ], title=None): proj = ccrs.PlateCarree() cmap = plt.get_cmap('Spectral_r') norm = BoundaryNorm(levels, ncolors=cmap.N, clip=True) # --shp数据 shp_path = '/home/qxs/bma/shp/fish_shp/' ax = self.map() fishcell = geopandas.read_file(shp_path + 'FishCellALL.shp') ax.add_geometries(fishcell.geometry, crs=proj, edgecolor='k', facecolor='none', zorder=9) # --风速数据 wind = self.ds['ws'] new_lon = np.linspace(wind.lon[0] - 0.25, wind.lon[-1] - 0.25, wind.lon.shape[0]) new_lat = np.linspace(wind.lat[0] - 0.25, wind.lat[-1] - 0.25, wind.lat.shape[0]) wind = wind.interp(lat=new_lat, lon=new_lon) wind_mask = wind.salem.roi(shape=fishcell).to_iris() # --画图 im = iplt.pcolor(wind_mask, cmap=cmap, axes=ax, norm=norm) # --画色标 cbr = plt.colorbar(im, fraction=0.06, pad=0.04, norm=norm) cbr.set_ticks(levels) # --标题 if self.ini_time != None and self.shift_hour != None: fcst_time = self.ini_time.shift( hours=self.shift_hour).format('YYYY-MM-DD HH:mm') ini_time = self.ini_time.format('YYYY-MM-DD HH:mm') title = '渔区风速图 \n 预报时间:{} UTC \n初始时间:{} UTC'.format( fcst_time, ini_time) ax.set_title(title, fontsize=18) # --存图 plt.savefig(self.path + 'ws_fishcell_{}_{}.png'.format( self.ini_time.format('YYYYMMDDHH'), str(self.shift_hour))) # plt.show() else: ax.set_title(title, fontsize=18) plt.show()
def add_cube(self, cube, kind='pcolormesh', **kwargs): if self.symmetric_colorbar: max_mag = max(abs(cube.data.min()), abs(cube.data.max())) self.val_max_magnitude = max(max_mag, self.val_max_magnitude) vmin = -self.val_max_magnitude vmax = self.val_max_magnitude kwargs.setdefault('vmin', vmin) kwargs.setdefault('vmax', vmax) kwargs.setdefault('zorder', 2) if kind == 'pcolormesh': p = iplt.pcolormesh(cube, axes=self.ax, **kwargs) elif kind == 'pcolor': p = iplt.pcolor(cube, axes=self.ax, **kwargs) elif kind == 'contourf': p = iplt.contourf(cube, axes=self.ax, **kwargs) elif kind == 'contour': p = iplt.contour(cube, axes=self.ax, **kwargs) else: raise RuntimeError('Unknown plot kind: {:}'.format(kind)) return p
def test_pcolor(self): cube = self.cube[0, 0] iplt.pcolor(cube) self.check_graphic()
def test_xaxis_labels(self): iplt.pcolor(self.cube, coords=('str_coord', 'bar')) self.assertBoundsTickLabels('xaxis')
def pcolor_mask_geoms(cube, geoms, transform): path = Path.make_compound_path(*geos_to_path(geoms)) im = iplt.pcolor(cube) im.set_clip_path(path, transform=transform)
def pcolor_mask_geoms(cube, geoms, transform): path = Path.make_compound_path(*geos_to_path(geoms)) im = iplt.pcolor(cube) im.set_clip_path(path, transform=transform) # First plot the full map: cube = iris.load_cube( '/RESEARCH/paper_ocean_heat_carbon/data/newCO2_control_800/sst.nc') cube = cube[0, :, :] plt.figure(figsize=(12, 6)) ax1 = plt.axes(projection=ccrs.PlateCarree()) ax1.coastlines() iplt.pcolor(cube) ''' # Now plot just the required countries: plt.figure(figsize=(12, 6)) ax2 = plt.axes(projection=ccrs.PlateCarree()) ax2.coastlines() countries = [ 'United States', 'United Kingdom', 'Saudi Arabia', 'South Africa', 'Nigeria'] geoms, transform = get_geometries(countries) pcolor_mask_geoms(cube, geoms, transform(ax2)) ''' plt.show()