我试图绘制地图上某一区域的等高线图,我可以毫无问题地在地图上创建等高线,但是当我将范围设置为下面的范围时,不管有没有等高线图,我都会得到下面的错误(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发布于 2022-09-18 00:42:58
变化
ax.set_extent([-140, -60, 20, 70], crs=ccrs.Mercator()) (因为值和crs不匹配)
至
ax.set_extent([-140, -60, 20, 70], crs=ccrs.PlateCarree())https://stackoverflow.com/questions/73532735
复制相似问题