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
相关产品推荐
相关产品推荐

