【问题标题】:Geopandas map layeringGeopandas 地图分层
【发布时间】:2020-07-06 05:13:17
【问题描述】:

我正在学习使用以下代码在 Spyder IDE 中使用 geopandas 包创建“分层”地图:

import geopandas as geopandas
import matplotlib.pyplot as plt


world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))

world.plot()

ax = plt.subplot(1, 1)
world.plot(column='pop_est', ax=ax, legend=True)

我像在 RStudio 中一样逐行执行代码。 不幸的是,我只能得到一张白色的空白纸而不是地图。

【问题讨论】:

  • 你能分享你的输出图像吗?你到底想要什么?与geopandas 文档中的内容相同?
  • @linog,是的,这正是我想要复制的内容。
  • 我的回答有帮助还是我错过了重点?

标签: python geopandas


【解决方案1】:

我在Jupyter 上运行了该示例,但我认为只要您安装了软件包,它就不会改变任何东西。

f, ax = plt.subplots(1,1,figsize=(10,10))
world.plot(column='pop_est', ax=ax, legend=True)

如果您只对几何感兴趣,可以执行以下操作:

world.geometry.plot(color="white", edgecolor='k')

如果将来您想将此几何图形添加到地图中,您可以这样做

world.geometry.plot(color=None, edgecolor='k')

【讨论】:

  • 非常有帮助,谢谢,代码在 Jupiter 和 Spyder 中都可以使用!
猜你喜欢
  • 2019-09-05
  • 2022-01-10
  • 2019-08-06
  • 2017-01-06
  • 2020-03-04
  • 2015-10-23
  • 2016-11-30
  • 2021-08-21
  • 1970-01-01
相关资源
最近更新 更多