【问题标题】:Why does the colorbar do not appear in my cloropleth map?为什么颜色条没有出现在我的等值线图中?
【发布时间】:2020-05-25 07:09:11
【问题描述】:

我已经绘制了一个 cloropleth 地图。但是颜色条没有正确显示。

这是我正在使用的数据框:

这是我的代码:

ax=new_df.plot(figsize=(18,16), column='count', cmap='Blues', k=5, legend=True)
plt.title("Number of IPs by district - Ontario")
ax.set_axis_off()

这就是我所拥有的:

【问题讨论】:

  • 看看new_df.dtypes。您的 'count' 列可能是字符串的对象列。将它们转换为数字。颜色是正确的,因为仍然可以对字符串进行排序,但是制作连续的图例并不像数字类型那样有意义。

标签: python-3.x pandas matplotlib geopandas


【解决方案1】:

问题在于“count”列的类型是 Object。因此,在将其转换为数字后,可以绘制颜色条以及 cloropleth 地图。

#Converting to numeric
new_df['count'] = new_df['count'].astype('int16')
new_df.dtypes

#Plotting
ax=new_df.plot(figsize=(12,12), column='count', cmap='Blues', k=5, legend=True)
plt.title("Number of IPs by district - Ontario")
ax.set_axis_off()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 2019-12-22
    相关资源
    最近更新 更多