Cartopy Contourf和Coastlines,但海岸线显示出来
我正在尝试使用Cartopy的轮廓和海岸线绘制从GESC Earthdata档案中下载的区域的降水数据,但是由于某种原因,只有数据的CMAP才显示出来,并且数据被数据掩盖了海岸线。这是我的绘图代码。
plt.clf() #clear figure before
fig=plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=100.0, globe=None))
ax.set_extent([95,106,0,9]) # lon_left, lon_right, lat_below, lat_upper
ax.coastlines("10m", alpha=0.1) # avail:110m, 50m, 10m..... '10m' is better resolution than default
ax.gridlines(linewidths=0.01, draw_labels=True, alpha= 0.3)
ax.xlocator = mticker.FixedLocator(np.arange(95.,106.,0.5))
ax.ylocator = mticker.FixedLocator(np.arange(0.,9.,0.5))
x,y=np.meshgrid(lat,lon)
clevs = np.arange(5,800,50)
cs = ax.contourf(y, x, finalmean, levels=clevs, extend="max", cmap='viridis_r', transform=ccrs.PlateCarree())
# draw legend -------------
#cax = fig.add_axes([0.1,0.018,0.8,0.05], projection=ccrs.PlateCarree()) #plot cb at the bottom [left, bottom, width, height]
#aa=fig.colorbar(cs,cax=cax,orientation='horizontal')
aa.set_label('Rainfall (mm)')
#plt.savefig("trmm_clim_mo_1.jpg", bbox_inches='tight')
plt.show()
这是我的输出
我还指定了plt.contourf中的“变换”参数为受到遇到同样问题但无济于事的人的建议。如果有人可以指出我缺少的/错的代码,那将非常感谢。
I'm trying to plot precipitation data of a region downloaded from GESC Earthdata archive using cartopy's contourf and coastlines but for some reason only the cmap of data is showing and the coastlines are undershadowed by the data. Here's my code for the plotting.
plt.clf() #clear figure before
fig=plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=100.0, globe=None))
ax.set_extent([95,106,0,9]) # lon_left, lon_right, lat_below, lat_upper
ax.coastlines("10m", alpha=0.1) # avail:110m, 50m, 10m..... '10m' is better resolution than default
ax.gridlines(linewidths=0.01, draw_labels=True, alpha= 0.3)
ax.xlocator = mticker.FixedLocator(np.arange(95.,106.,0.5))
ax.ylocator = mticker.FixedLocator(np.arange(0.,9.,0.5))
x,y=np.meshgrid(lat,lon)
clevs = np.arange(5,800,50)
cs = ax.contourf(y, x, finalmean, levels=clevs, extend="max", cmap='viridis_r', transform=ccrs.PlateCarree())
# draw legend -------------
#cax = fig.add_axes([0.1,0.018,0.8,0.05], projection=ccrs.PlateCarree()) #plot cb at the bottom [left, bottom, width, height]
#aa=fig.colorbar(cs,cax=cax,orientation='horizontal')
aa.set_label('Rainfall (mm)')
#plt.savefig("trmm_clim_mo_1.jpg", bbox_inches='tight')
plt.show()
Here's my output
I've also specified the "transform" argument in the plt.contourf as advised by those who'd encountered this same problem but to no avail. If anyone can point out what I'm missing/wrong with my code, that'd be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用matplotlib kwarg zorder 彼此之间的层面。在您的示例中:
ax.coastlines(“ 10m”,alpha = 0.1,zorder = 3)
应该做。具有较低Zorder的对象具有较高的Zorder图。
或者,添加您的海岸线 呼叫轮廓。默认情况下,层添加的层将添加到前任之上。
Try using the matplotlib kwarg zorder to set which layers plot on top of each other. In you example:
ax.coastlines("10m", alpha=0.1, zorder=3)
should do. Objects with higher zorder plot on top of those with lower zorder.
Alternatively, add your coastlines after the call to contourf. By default, layers you add later get added on top of the predecessors.