【问题标题】:Plot not showing after plt.show(), gives no error 'and only shows : <Figure size 432x288 with 0 Axes>'在 plt.show() 之后绘图未显示,没有错误'并且仅显示:<Figure size 432x288 with 0 Axes>'
【发布时间】:2020-01-21 18:50:31
【问题描述】:

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

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

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>

我能做些什么呢?谢谢。

【问题讨论】:

  • 它是否适用于链接中显示的数据集?
  • 我现在用链接中的数据进行了尝试,它显示了相同的结果:Figure size 432x288 with 0 Axes>
  • Mhh,我在从链接尝试笔记本时遇到this problem(似乎并非所有需要的文件都在 repo 中);这意味着我无法提供更多帮助。

标签: matplotlib figure geopandas


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    如果您的 matplotlib ax 实例和 merge.plot() 位于 Jupyter Notebook 的不同代码单元格中,并且首先生成 ax 实例,请考虑将 ax 实例和 merge.plot() 放在同一单元格中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多