用不同的 `central_longitude` 改变 `cartopy` 上的 `ylim`

问题描述 投票:0回答:1

我想在墨卡托投影上创建一个从 -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

它回来了

我的问题是:

  1. 为什么
    cartopy
    会这样?
  2. 我该如何解决这个问题?
python matplotlib gis cartopy
1个回答
0
投票

您需要在相关选项参数中指定正确的值。默认值并不总是有效。

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

© www.soinside.com 2019 - 2024. All rights reserved.