我有从数据框读取并用X&Y绘制直方图的python脚本。问题是当我尝试绘制选定的文件以绘制系统崩溃并显示以下错误时:
Traceback (most recent call last) <ipython-input-37-12c65f478c54> in <module>
4 plt.figure(figsize=(12,6))
5 plt.xlim(0,45)
----> 6 plt.xlabel("word count")
7 plt.ylabel("frequency")
8 g = plt.hist([x,y],color=["r","b"],alpha=0.5,label=["positive","negative"])
TypeError: 'str' object is not callable
#plot word count distribution for both positive and negative sentiment
x= df_tweet_preds["word count"][df_tweet_preds.predictions ==1]
y= df_tweet_preds["word count"][df_tweet_preds.predictions ==0]
plt.figure(figsize=(12,6))
plt.xlim(0,45)
plt.xlabel("word count")
plt.ylabel("frequency")
g = plt.hist([x,y],color=["r","b"],alpha=0.5,label=["positive","negative"])
plt.legend(loc="upper right")
ax.set_xlabel('Smarts')
ax.set_ylabel('Probability density')
plt.show()