定义 cartopy 上墨卡托投影的纵向范围

use*_*915 1 python matplotlib cartopy jupyter-notebook

我试图绘制一些作为矩阵存在的数据,例如温度。这些数据是区域性的,所以我不需要全球地图。

我有:

  1. 数据矩阵 (mxn)
  2. 定义纬度(mx1)和经度(nx1)的向量

我想使用带有墨卡托投影的 cartopy 来绘制它。但是,墨卡托只允许我定义最小和最大纬度,而不是最小和最大经度。这最终给了我一大片土地。

Mercator(central_longitude=103.0,min_latitude=gridlat[0],max_latitude=gridlat[-1])
Run Code Online (Sandbox Code Playgroud)

我将如何设置沿海地图的最小和最大经度?最终,我只想绘制我的数据,并在其上覆盖国家边界,就像使用 ncview 时的外观一样。

ajd*_*son 5

选择投影时通常不会设置地图的范围,您可以稍后使用set_extent您创建的轴的方法进行设置。实际上,cartopy 中的默认行为是根据绘制的数据拟合范围,因此您想要的应该是使用普通墨卡托投影绘制绘图时发生的情况。以下是在地理坐标中明确设置范围的示例:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt

# Create Mercator projection with dateline in the middle:
ax = plt.axes(projection=ccrs.Mercator(central_longitude=180))
# Draw coastlines so we know where we are:
ax.coastlines()
# Set the map extent, making sure to specify the correct coordinate system
# for geographical coordinates:
ax.set_extent([90, 270, -40, 40], crs=ccrs.PlateCarree())
plt.show()
Run Code Online (Sandbox Code Playgroud)