【问题标题】:Cartopy issue with extent (free(): invalid size)Cartopy 范围问题(free():无效大小)
【发布时间】:2022-12-09 05:14:55
【问题描述】:

我正在使用 Cartopy,我正在努力解决这个问题free(): invalid size。它发生在我设置地图范围时。

extents = [-13, 44, 34, 63] # Europe
proj = cartopy.crs.PlateCarree(central_longitude=(extents[1]-extents[0])/2)
ax = fig.add_subplot(
    nrows,
    ncols,
    index,
    projection=proj,
)
ax.set_extent(extents=extents, crs=proj)

我尝试了 pyplot.subplotpyplot.axes 等几个函数,但似乎都无济于事。

你能给我解释一下这个错误是什么以及如何解决吗?

编辑:

在这里你可以找到我正在使用的包列表:

Cartopy==0.20.2
  - matplotlib [required: >=3.1, installed: 3.5.1]
    - cycler [required: >=0.10, installed: 0.11.0]
    - fonttools [required: >=4.22.0, installed: 4.29.1]
    - kiwisolver [required: >=1.0.1, installed: 1.3.2]
    - numpy [required: >=1.17, installed: 1.21.5]
    - packaging [required: >=20.0, installed: 21.3]
      - pyparsing [required: >=2.0.2,!=3.0.5, installed: 3.0.7]
    - pillow [required: >=6.2.0, installed: 9.0.1]
    - pyparsing [required: >=2.2.1, installed: 3.0.7]
    - python-dateutil [required: >=2.7, installed: 2.8.2]
      - six [required: >=1.5, installed: 1.16.0]
  - numpy [required: >=1.18, installed: 1.21.5]
  - pyproj [required: >=3.0.0, installed: 3.3.0]
    - certifi [required: Any, installed: 2021.10.8]
  - pyshp [required: >=2.1, installed: 2.2.0]
  - shapely [required: >=1.6.4, installed: 1.8.1.post1]

【问题讨论】:

  • 我将 nrowsncolsindex 设置为 1,但没有出现错误,这让我想知道这是否是您的 cartopy 版本的问题。
  • 是的。我通常使用此值,但收到相同的错误消息。我用 cartopy 依赖项列表更新了我的第一条消息。我没有看到包安装中的错误。
  • 一件明显错误的事情是ax.set_extent(extents=extents, crs=proj)。您必须使用ax.set_extent(extents=extents, crs=cartopy.crs.PlateCarree())。因为范围值是基于其中心经度为零的标准投影。由于零是默认值,因此您可以省略它。

标签: python matplotlib cartopy


【解决方案1】:

我有同样的问题。将 shapely 的版本从 1.8.1.post1 更改为 1.7.1 解决了问题

【讨论】:

    【解决方案2】:

    正如https://github.com/SciTools/cartopy/issues/2006 所描述的,这个问题只出现在 shapely 1.8.1(和 1.8.1.post1)什么时候安装了轮子(pip 的标准行为)。

    正如 greglucas 在问题中解释的那样,通过 pip install --upgrade --no-binary shapely shapely 安装。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-10
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多