为什么颜色条没有出现在我的圆形图中?

问题描述 投票:0回答:1

我已经绘制了一个圆形图。但是颜色栏不能正确显示。

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

enter image description here

这是我的代码:

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()

这是我所拥有的:

enter image description here

python-3.x pandas matplotlib geopandas
1个回答
0
投票

问题是列'count'的类型为Object。因此,将其转换为数字后,就可以绘制颜色条以及圆形图。

enter image description here

#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()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.