You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.6中matplotlib报错:module 'matplotlib' has no attribute 'bar'求助

问题解决:AttributeError: module 'matplotlib' has no attribute 'bar'

错误根源有两处:

  • 导入matplotlib的方式错误:bar、xlabel这类绘图函数都属于matplotlib.pyplot子模块,而非matplotlib主模块的属性,所以不能直接把matplotlib本身别名为plt。
  • 函数名拼写错误:xlable和ylable是笔误,正确写法是xlabel和ylabel。

修正后的完整代码:

import numpy as np
import pandas as pd
# 修正导入路径
import matplotlib.pyplot as plt
import seaborn as sb

smartphone = pd.read_csv("C://Users/Admin/smartphones.csv")

count = smartphone.Ram.value_counts()
category = count.index
plt.bar(category,count)
# 修正拼写错误
plt.xlabel('Ram')
plt.ylabel('Count')
plt.xticks([1,2,3,4])
plt.yticks([1,2,3])
plt.show()

内容的提问来源于stack exchange,提问作者MGH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 08:56:05