我正在尝试在地图上绘制某个区域的等高线图,我可以毫无问题地在地图上创建等高线图,但是当我按如下方式设置范围时,无论有或没有等高线图,我都会收到错误下面(Cartopy 版本 0.20.3):
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
p = ccrs.Mercator()
ax = plt.axes(projection=p)
ax.set_extent([-140, -60, 20, 70], crs=ccrs.Mercator())
ax.coastlines()
ax.gridlines()
plt.show()
TypeError Traceback (most recent call last) Input In [5], in <cell line: 7>()
5 p = ccrs.Mercator()
6 ax = plt.axes(projection=p)
----> 7 ax.set_extent([-140, -60, 20, 70], crs=ccrs.Mercator())
8 ax.coastlines()
9 ax.gridlines()
File ~\Anaconda3\envs\geospatial\lib\site-packages\cartopy\mpl\geoaxes.py:904,
in GeoAxes.set_extent(self, extents, crs)
901 projected = boundary
903 if projected is None:
--> 904 projected = self.projection.project_geometry(domain_in_crs, crs)
905 try:
906 # This might fail with an unhelpful error message ('need more
907 # than 0 values to unpack') if the specified extents fall outside
908 # the projection extents, so try and give a better error message.
909 x1, y1, x2, y2 = projected.bounds
File ~\Anaconda3\envs\geospatial\lib\site-packages\cartopy\crs.py:805, in Projection.project_geometry(self, geometry, src_crs)
803 if not method_name:
804 raise ValueError(f'Unsupported geometry type {geom_type!r}')
--> 805 return getattr(self, method_name)(geometry, src_crs)
File ~\Anaconda3\envs\geospatial\lib\site-packages\cartopy\crs.py:811, in Projection._project_line_string(self, geometry, src_crs)
810 def _project_line_string(self, geometry, src_crs):
--> 811 return cartopy.trace.project_linear(geometry, src_crs, self)
File lib/cartopy/trace.pyx:628, in cartopy.trace.project_linear()
File lib/cartopy/trace.pyx:100, in cartopy.trace.geos_from_shapely()
TypeError: an integer is required
改变
ax.set_extent([-140, -60, 20, 70], crs=ccrs.Mercator())
因为值和
crs
不匹配,即值[-140, -60, 20, 70]
要求crs=ccrs.PlateCarree()
。
到
ax.set_extent([-140, -60, 20, 70], crs=ccrs.PlateCarree())