',matplotlib,figure,geopandas"/>

首页 > 解决方案 > 在 plt.show() 之后绘图未显示,没有错误,仅显示:

'

问题描述

我正在尝试使用 shapefile 和数据框绘制地理数据,(按照此链接中的说明操作: https ://towardsdatascience.com/lets-make-a-map-using-geopandas-pandas-and-matplotlib- to-make-a-chloropleth-map-dddc31c1983d)通过合并它们,然后尝试绘制地理数据。

这里 map_df 是 geopandas 读取的 shapefile,df 是地理统计数据的数据框。

merged = map_df.set_index('NAME_3').join(df.set_index('City'))


variable = 'Rate'
vmin, vmax = 120, 220
fig, ax = plt.subplots(1, figsize=(10, 6))

merged.plot(column=variable, cmap = 'Blues', linewidth=0.8, ax=ax)
plt.show()

在链接中有 'edgecolor='0.8'' 变量,但它在我的代码中产生了 RGBA 错误,这就是我删除该部分的原因。现在,即使我使用 plt.show() 它也不会显示情节,只会说:

 <Figure size 432x288 with 0 Axes>

我能做些什么呢?谢谢你。

标签: matplotlibfiguregeopandas

解决方案


我使用 jupyter 笔记本遇到了这个确切的问题。为我解决这个问题的唯一方法是创建一个新笔记本。它突然起作用了。


推荐阅读