首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cartopy set_extent()错误

Cartopy set_extent()错误
EN

Stack Overflow用户
提问于 2022-08-29 17:46:59
回答 1查看 131关注 0票数 0

我试图绘制地图上某一区域的等高线图,我可以毫无问题地在地图上创建等高线,但是当我将范围设置为下面的范围时,不管有没有等高线图,我都会得到下面的错误(Cartopy版本0.20.3):

代码语言:javascript
复制
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()
代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2022-09-18 00:42:58

变化

代码语言:javascript
复制
ax.set_extent([-140, -60, 20, 70], crs=ccrs.Mercator()) 

(因为值和crs不匹配)

代码语言:javascript
复制
ax.set_extent([-140, -60, 20, 70], crs=ccrs.PlateCarree())
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73532735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档