当我尝试标记我的情节时出现这种类型错误

时间:2021-01-10 16:06:51

标签: python matplotlib

bins=[0, 2500, 4000, 6000, 81000] 
group=['Low', 'Average', 'High', 'Very High']
train['Income_bin']=pd.cut(train['ApplicantIncome'],bins,labels=group)
Income_bin=pd.crosstab(train['Income_bin'], train['Loan_Status'])
Income_bin.div(Income_bin.sum(1).astype(float), axis=0).plot(kind='bar', stacked=True)

plt.xlabel('ApplicantIncome')
P= plt.ylabel('Percentage')

错误:

TypeError         Traceback (most recent call last)
<ipython-input-121-edc3284103c2> in <module>

   7 Income_bin.div(Income_bin.sum(1).astype(float), axis=0).plot(kind='bar', stacked=True)
      8 
----> 9 plt.xlabel('ApplicantIncome')
     10 P= plt.ylabel('Percentage')

TypeError: 'str' object is not callable

1 个答案:

答案 0 :(得分:0)

不要将 plt.ylabel('Percenatge') 分配给任何变量

像这样:

import matplotlib.pyplot as plt
x=[1,2,3,4,5,6]
y=[12,23,9,14,15,19]
plt.plot(x,y)
aplt.xlabel('X-Label')
plt.ylabel('Y-Label')
plt.show()

注意:我假设您正在 matplotlib 中绘制基本图形。

相关问题