映射盒子轮廓。有PColor的映射替代品吗?
我创建了一个映射,使用Cartopy'contouf'
我想知道我是否有一种方法可以更改地图,以免插入插入,因此每个网格正方形将是一种纯色(但不会绕极旋转):
从我研究的内容中,这些被称为块图,可以使用'pcolormesh'制作。这是我尝试的:
precip_full1 = xr.open_dataset('era_yr1979.nc')
precip_full2 = xr.open_dataset('era_yr1980.nc')
precip_full3 = xr.open_dataset('era_yr1981.nc')
precip_full = xr.concat([precip_full1,precip_full2,precip_full3],dim='time')
output = []
for x in np.arange(6.5,10.25,0.25):
for y in np.arange(-15,-9.75,0.25):
precip = precip_full.where((precip_full.latitude==x)&(precip_full.longitude==y),drop=True)
roll = precip.rolling(time=6,center=False).sum()
annual = roll.groupby('time.year').max()
tab = annual.to_dataframe().rename(columns={'tp':6})
output.append(tab)
output = pd.concat(output,1)
mean = output.mean()
data_mean = pd.DataFrame(mean, columns=['mean'])
df = data_mean.to_numpy()
new = [df[i:i+21] for i in range(0,len(df),21)]
new = np.reshape(new, [-1, 21])
df = pd.DataFrame(data=new, dtype=object)
lon2d, lat2d = np.meshgrid(lon, lat)
plt.figure(figsize=(6,5))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-15,-10,6.5,10])
ax.coastlines()
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.LAKES)
ax.add_feature(cfeature.RIVERS)
gl = ax.gridlines(draw_labels=True, xlocs=np.arange(-180,180,0.25), ylocs=np.arange(-90,90,0.25),linewidth=0.4)
gl.top_labels = False
gl.right_labels = False
plot = plt.pcolor(lon2d, lat2d, df, cmap = 'jet', transform=ccrs.PlateCarree())
我遇到错误:
TypeError: Dimensions of C (15, 21) are incompatible with X (15) and/or Y (15)
有人可以在这里看到我在做错什么,还是有更容易的选择?
I have created a map that interpolates values between gridpoints, using Cartopy 'contouf'
I'm wondering if there is a way I can change the map so that it doesn't interpolate, and so instead each grid square will be a solid color, like this (but not rotated around the pole):
From what I've researched, these are called block plots, which can be made using 'pcolormesh'. This is what I've tried:
precip_full1 = xr.open_dataset('era_yr1979.nc')
precip_full2 = xr.open_dataset('era_yr1980.nc')
precip_full3 = xr.open_dataset('era_yr1981.nc')
precip_full = xr.concat([precip_full1,precip_full2,precip_full3],dim='time')
output = []
for x in np.arange(6.5,10.25,0.25):
for y in np.arange(-15,-9.75,0.25):
precip = precip_full.where((precip_full.latitude==x)&(precip_full.longitude==y),drop=True)
roll = precip.rolling(time=6,center=False).sum()
annual = roll.groupby('time.year').max()
tab = annual.to_dataframe().rename(columns={'tp':6})
output.append(tab)
output = pd.concat(output,1)
mean = output.mean()
data_mean = pd.DataFrame(mean, columns=['mean'])
df = data_mean.to_numpy()
new = [df[i:i+21] for i in range(0,len(df),21)]
new = np.reshape(new, [-1, 21])
df = pd.DataFrame(data=new, dtype=object)
lon2d, lat2d = np.meshgrid(lon, lat)
plt.figure(figsize=(6,5))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-15,-10,6.5,10])
ax.coastlines()
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.LAKES)
ax.add_feature(cfeature.RIVERS)
gl = ax.gridlines(draw_labels=True, xlocs=np.arange(-180,180,0.25), ylocs=np.arange(-90,90,0.25),linewidth=0.4)
gl.top_labels = False
gl.right_labels = False
plot = plt.pcolor(lon2d, lat2d, df, cmap = 'jet', transform=ccrs.PlateCarree())
For which I get the error:
TypeError: Dimensions of C (15, 21) are incompatible with X (15) and/or Y (15)
Can anyone see what I'm doing wrong here, or is there an easier alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论