映射盒子轮廓。有PColor的映射替代品吗?

发布于 2025-01-22 12:09:10 字数 2049 浏览 2 评论 0原文

我创建了一个映射,使用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'

enter image description here

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):

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文