AttributeError:模块“matplotlib”没有属性“xlabel”

Sim*_*not 3 python matplotlib attributeerror

我的代码是:

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);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

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'
Run Code Online (Sandbox Code Playgroud)

可能会出现什么问题?

Mur*_*nik 7

你的import说法是错误的。这些方法属于pyplot. 即,您应该像这样导入它:

import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)