python - 如何在 jupyter notebook 上使用 python 中的 pyplot 包绘制直方图
问题描述
我正在尝试在 jupyter Notebook 上绘制直方图,其中数据是从数据框中提取的,以可视化所用数据集中每条记录的正面和负面情绪。
问题是,一旦我尝试绘制结果,就会显示以下错误并显示一个空的可视化。
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-37-8903e5cb1735> in <module>
5 plt.figure(figsize=(12,6))
6 plt.xlim(0,45)
----> 7 plt.xlabel("word count")
8 plt.ylabel("frequency")
9 g = plt.hist([x,y],color=["r","b"],alpha=0.5,label=["positive","negative"])
TypeError: 'str' object is not callable
代码
import matplotlib.pyplot as plt
#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")
解决方案
推荐阅读
- mysql - 如何在sql中找到具有多个最大值的组的最大值?
- azure - 跨订阅的 Azure 应用程序网关 WAFv2
- javascript - ServiceWorkers 和 ServiceWorkerContainer.prototype.register 如何用于指纹识别和机器人检测
- java - 使用 SimpleJdbcCall 调用存储过程时如何处理 clob 返回
- python - 了解 NVLabs/noise2noise 中的 tf.data 管道
- java - Java应用程序在初始化时返回超类
- delphi - 关注 TStringGrid 中的任意行/列
- spring - 未找到 Spring Boot 2 执行器配置属性源
- r - 是否可以在 ggplot2 中的多行上显示 x 轴变量
- java - 如何使流减少是线程安全的?