我的代码是:
import matplotlib as plt
sns.distplot(CMSU['Spending'], kde = False)
plt.xlabel("Spending", size=15)
plt.ylabel("Probablity", size=15)
plt.title("Distribution for the variable - Spending", size=18);
我得到了错误:
AttributeError Traceback (most recent call last)
<ipython-input-32-1c6eb744a592> in <module>
1 sns.distplot(CMSU['Spending'], kde = False)
----> 2 plt.xlabel("Spending", size=15)
3 plt.ylabel("Probablity", size=15)
4 plt.title("Distribution for the variable - Spending", size=18);
AttributeError: module 'matplotlib' has no attribute 'xlabel'
有什么可能出错呢?
4条答案
按热度按时间zyfwsgd61#
你的
import
语句是错误的。这些方法属于pyplot
。也就是说,你应该像这样导入它:ylamdve62#
我认为你需要做
import matplotlib.pyplot as plt
而不仅仅是matplotlib as plt
,因为xlabel
和其他各种函数在matplotlib中不存在。nukf8bse3#
用途:
ylabel
和title
也是一样:v6ylcynt4#
AttributeError Traceback(most recent call last)in()2 plt. title("Videos are strongly correlated with clicking")3 www.example.com(["Page Load","Video Watching","Reading Pricing"],[-0.39,0.67,0.0004])----> 4 plt. ylabl("Correlation With Clicking")<cell line: 4>() 2 plt.title("Videos are strongly correlated with clicking") 3 plt.bar (["Page Load", "Video Watching", "Reading Pricing"], [-0.39, 0.67, 0.0004]) ----> 4 plt.ylabl("Correlation With Clicking")
属性错误:module 'matplotlib. pyplot' has no attribute 'ylabl我以前运行过同样的代码,结果成功了,不知道现在发生了什么!!!