37,719
社区成员
发帖
与我相关
我的任务
分享
import numpy as np
import matplotlib
x = np.arange(len(df_0_age)) # the label locations
width = 0.35 # the width of the bars
labels=df_0_age['区间'].values
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2,df_0_age['占比/排名_其他'], width, label='其他')
rects2 = ax.bar(x + width/2,df_0_age['占比/排名_云南'], width, label='云南')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('占比')
ax.set_title('0')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)
确实使用较新版本的matplotlib就可以了,但是新版的 matplotlib 只支持 python3.7 以上
版本问题,原来我是3.3.2版本的 卸载重装最新的3.4.2就可以了