【问题标题】:Plotting a heatmap (kernel density) using geopandas + geoplot crashes session使用 geopandas + geoplot crash session 绘制热图(内核密度)
【发布时间】:2021-11-04 11:16:46
【问题描述】:

我最近在a question 上发布了关于如何使用 geopandas 绘制热图的帖子。建议我使用geoplot.kdeplot(),但传递projection 会使我的会话崩溃。

假设我在df_pointsdf_map 分别存储了以下数据:

> print(df_points)
        PointID                     geometry
0     204403876  POINT (-101.66700 21.11670)
1     204462769  POINT (-101.66700 21.11670)
2     144407530  POINT (-101.66700 21.11670)

> print(df_map)
     PolyID                                           geometry
0     01001  POLYGON ((-102.10641 22.06035, -102.10368 22.0...
1     01002  POLYGON ((-102.05189 22.29144, -102.05121 22.2...
2     01003  POLYGON ((-102.68569 22.09963, -102.69087 22.0...

这是我尝试过的,但根据this tutorial,我应该将projection 传递给热图。

# Import geoplot
import geoplot
import geoplot.crs as gcrs

# Plot points
ax = geoplot.kdeplot(df_points, shade=True, alpha=0.7)
# Plot polygons
geoplot.polyplot(df_map, ax=ax)

但是,如果我添加 projection=gcrs.AlbersEqualArea(),我的会话会崩溃:

# Plot heatmap
ax = geoplot.kdeplot(df_points, cmap='Reds', shade=True,
                     projection=gcrs.AlbersEqualArea()) # This crashes my session ):
# Add polygons
geoplot.polyplot(df_map, ax=ax)

python3: geos_ts_c.cpp:3991: int GEOSCoordSeq_getSize_r(GEOSContextHandle_t, const geos::geom::CoordinateSequence*, unsigned int*): 断言 `0 != cs' 失败。

如何传递projection=gcrs.AlbersEqualArea() 并避免错误?

【问题讨论】:

    标签: python matplotlib geopandas kernel-density geoplot


    【解决方案1】:

    我在评论上一个问题:我刚刚在 Colab 的官方 geoplot 参考中运行了示例,并遇到了类似的崩溃。经过一番研究,我发现崩溃是由 shaply 引起的,然后将其卸载并重新安装,并根据参考显示图表。请试一试。

    pip uninstall shapely
    pip install shapely --no-binary shapely
    

    这是帮助我的answers

    【讨论】:

    • 实际的Colab 可以在这里找到。请参考如果您确认,我们将删除它。
    猜你喜欢
    • 2019-05-11
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2018-01-23
    相关资源
    最近更新 更多