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 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口