如何修复'str'对象不可调用?使用matplotlib吗?

问题描述 投票:0回答:1

我有从数据框读取并用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

code

#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")

this is how  it display empty

python matplotlib sentiment-analysis
1个回答
0
投票
ax.set_xlabel('Smarts')
ax.set_ylabel('Probability density')
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.