我想在墨卡托投影上创建一个从 -60S 到 60N 但以 -160W 为中心经度的地图。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure()
ax = fig.add_subplot(1,1,1,
projection=ccrs.PlateCarree(central_longitude=0)
)
ax.set_extent([-180,180,-60,60])
ax.coastlines(resolution='110m')
ax.gridlines(draw_labels=True)
返回
central_longitude=0
的预期结果
但是如果
central_longitude=-60
它回来了
我的问题是:
cartopy
会这样?您需要在相关选项参数中指定正确的值。默认值并不总是有效。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
noproj = projection=ccrs.PlateCarree() #central_longitude=0
myproj = projection=ccrs.PlateCarree(central_longitude=-60)
fig = plt.figure()
ax = fig.add_subplot(1,1,1,
projection = myproj
)
# *** Dont use 180 but 179.95 to avoid mysterious error
# longitudes -180 and +180 are sometimes interpreted as the same location
# Also specify `crs` correctly
ax.set_extent([-179.95, 179.95, -60, 60], crs=noproj)
# In the more recent versions of Cartopy, you can use [-180,180,-60,60]
ax.coastlines(resolution='110m')
ax.gridlines(draw_labels=True)
plt.show()