我正试图绘制喀麦隆上空的降水图,只给喀麦隆边界的内侧加上阴影。
所有其他国家都将被屏蔽。
下面是我正在使用的脚本的情节和开头:
import numpy as np
from scipy import stats
from netCDF4 import Dataset
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy
import cartopy.io.shapereader as shapereader
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.font_manager import FontProperties
ref_dat = Dataset("R95ptot_Kmer_chirps-v2.0.1981_2019.days_p05.nc", mode='r')
lat = ref_dat.variables["latitude"][:]
lon = ref_dat.variables["longitude"][:]
time = ref_dat.variables["time"]
pre0 = ref_dat.variables["precip"][:, :, :]
slope = np.zeros(pre0[0, :, :].shape)
intercept = np.zeros(pre0[0, :, :].shape)
r_value = np.zeros(pre0[0, :, :].shape)
p_value = np.zeros(pre0[0, :, :].shape)
std_err = np.zeros(pre0[0, :, :].shape)
for ilat in range(len(lat)):
for jlon in range(len(lon)):
slope[ilat, jlon], intercept[ilat, jlon], r_value[ilat, jlon], p_value[ilat, jlon], std_err[ilat, jlon] = stats.linregress(time, pre0[:, ilat, jlon])
[lons2d, lats2d] = np.meshgrid(lon, lat)
fig, ax = plt.subplots(1, 1, sharex=True, sharey=True, figsize=(8.5, 6.98),
subplot_kw={'projection':ccrs.PlateCarree()})
mymap = ax.contourf(lons2d, lats2d, slope,
transform=ccrs.PlateCarree(),
cmap=plt.cm.Spectral_r, extend='both')
最后我解决了我的问题。 这里是我要寻找的情节和使用的脚本
这里有一个有用的链接,用来解决我的问题
Python cartopy map, clip area outside country (polygon)
enter image description here
相关问题 更多 >
编程相关推荐