EricTintin 2021-04-19 13:29 采纳率: 100%
浏览 97
已采纳

python matplotlib.pyplot 官网示例代码出错?

引用https://matplotlib.org/stable/gallery/lines_bars_and_markers/barchart.html#sphx-glr-gallery-lines-bars-and-markers-barchart-py中的代码,提示没有bar_label方法!

以下是源代码:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np


labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]

x = np.arange(len(labels))  # the label locations
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()

ax.bar_label(rects1, padding=3)  # 问题出现了!!!
ax.bar_label(rects2, padding=3)  # 问题出现了!!!

fig.tight_layout()

plt.show()

更新了matplotlib包,也无济于事,快帮我看看是哪里出了问题???

  • 写回答

3条回答 默认 最新

  • kaili_ya 2021-04-20 11:09
    关注

     

    嗯,我也出错了

    这个是3.4.1版本才添加的,所以需要安装3.4.1版本的matplotlib,如果:

    conda install matplotlib==3.4.1

    没有成功,那就使用以下命令来查看可用版本:

    anaconda search -t conda matplotlib
    conda install -c https://conda.anaconda.org/conda-forge matplotlib==3.4.1

    发现可用版本后安装,成功后:

    没有再报错,成功解决!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 为什么eprime输出的数据会有缺失?
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题