Matplotlib报错 AttributeError: 'AxesSubplot' object has no attribute 'bar_label'

Morningstar? 2021-03-29 03:34:55
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)


我用官网的带这个bar_label函数的例子也是报错,版本3.3.4,跟官网没差多少,应该不是版本问题吧
...全文
5540 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
NewbeeLin 2022-06-29
  • 打赏
  • 举报
回复

确实使用较新版本的matplotlib就可以了,但是新版的 matplotlib 只支持 python3.7 以上

易小楠 2021-06-16
  • 打赏
  • 举报
回复

版本问题,原来我是3.3.2版本的 卸载重装最新的3.4.2就可以了

RPG_Zero 2021-05-24
  • 打赏
  • 举报
回复
更新matplotlib的版本解决了问题
yixintong1 2021-05-18
  • 打赏
  • 举报
回复
报错+1,求助!
Morningstar? 2021-05-18
  • 打赏
  • 举报
回复
引用 3 楼 qq_42445525 的回复:
请问下楼主解决了么?我也是官网下的代码报这个错误
还没有 你试试楼下的
weixin_43244340 2021-05-11
  • 打赏
  • 举报
回复
安装最新版本的matplotlib方法如下: python -m pip install -U pip python -m pip install -U matplotlib
LIWENYl 2021-05-05
  • 打赏
  • 举报
回复
请问下楼主解决了么?我也是官网下的代码报这个错误
Morningstar? 2021-04-21
  • 打赏
  • 举报
回复
'AxesSubplot' object has no attribute 'bar_label' 报错这个
Morningstar? 2021-04-21
  • 打赏
  • 举报
回复
这...这问题很难吗 我吐了
CV设计师 2022-11-06
  • 举报
回复
@Morningstar? 不难啊 那你还问

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧