matplotlib - 在 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>
我能做些什么呢?谢谢你。
解决方案
我使用 jupyter 笔记本遇到了这个确切的问题。为我解决这个问题的唯一方法是创建一个新笔记本。它突然起作用了。
推荐阅读
- python - Python向discord发送消息
- unix - 使用 sed 命令将双辅音字母替换为一个
- git - `git lfs track` 是否比写入 `.gitattributes` 更多?
- apple-push-notifications - WatchOS 6 通知未到达
- python - 使用 matplotlib.pyplot 使用连续变量为绘图着色
- c++ - 如何在向量中找到具有重复数字的数字?
- c - 使用 malloc 和不使用 malloc 创建结构的区别
- python - 逐对或三元组迭代列表
- python - Pygame wait for screen to update
- c++ - 在 c++11 和 c++17 中插入地图的方法?