我正在尝试在正交投影中放大一些Cartopy图,但使用简单的ax.set_extent()方法似乎不可能。我使用的代码如下:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure()
ax = plt.axes(projection = ccrs.Orthographic())
ax.set_global()
ax.set_extent((-120,120,50,90), crs = ccrs.PlateCarree())我收到以下错误:ValueError: Failed to determine the required bounds in projection coordinates.
实际上,我只需要设置一个较低的边界纬度来绘制极地区域,这是我以前使用底图时所做的。然而,我不知道如何继续Cartopy。
有什么方法可以做到这一点吗?
发布于 2019-02-07 20:44:52
这里的问题是您的经度范围太大,因为-120或120都不在中心经度/纬度为0的正交磁盘上(它们都在它的“后面”)。您可以首先查询全局经度范围是什么,然后使用该范围而不是(-120,120)。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure()
ax = plt.axes(projection = ccrs.Orthographic())
ax.set_global()
global_extent = ax.get_extent(crs=ccrs.PlateCarree())
ax.set_extent(global_extent[:2] + (50, 90), crs=ccrs.PlateCarree())
ax.coastlines()

发布于 2019-02-07 01:54:39
我确实有一些小问题,想像期望的具有受限坐标的正交投影看起来像什么--并且假设cartopy有类似的理解问题:-)。
当然,您可以使用不同的(可能更合适的)投影;LambertConformal可能更有意义。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure()
proj = ccrs.LambertConformal(central_longitude=-96.0, central_latitude=39.0, )
ax = plt.axes(projection = proj)
ax.set_extent((-120,120,50,90), crs = ccrs.PlateCarree())
ax.coastlines(resolution='110m')
ax.gridlines()
plt.show()

https://stackoverflow.com/questions/54557900
复制相似问题