Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用matplotlib打印列表时出现值错误(x和y必须具有相同的第一个维度)_Python_Matplotlib_Sentiment Analysis - Fatal编程技术网

Python 使用matplotlib打印列表时出现值错误(x和y必须具有相同的第一个维度)

Python 使用matplotlib打印列表时出现值错误(x和y必须具有相同的第一个维度),python,matplotlib,sentiment-analysis,Python,Matplotlib,Sentiment Analysis,我正在尝试为推特创建一个实时情绪分析图。该程序从本地存储的JSON文件加载数据,并将“created_at”数据转换为unix时间,同时使用VaderMotion分析文本并更新运行的情绪总数 fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) yar = [] total = [] created = [] sid = SentimentIntensityAnalyzer() #ss = sid.polarity_scores(sentence)

我正在尝试为推特创建一个实时情绪分析图。该程序从本地存储的JSON文件加载数据,并将“created_at”数据转换为unix时间,同时使用VaderMotion分析文本并更新运行的情绪总数

fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)

yar = []
total = []
created = []
sid = SentimentIntensityAnalyzer()
#ss = sid.polarity_scores(sentence)


def animate(i):

  compound_total = 0

  with open('python.json', 'r') as f:

    line = f.readline()
    for line in f:
      tweet = json.loads(line)
      #print(sid.polarity_scores(tweet['text']))
      total.append(sid.polarity_scores(tweet['text'])['compound'])
      created_at = tweet['created_at']
      tweet_time = time.mktime(time.strptime(created_at,"%a %b %d %H:%M:%S +0000 %Y"))
      created.append(tweet_time)


    for each in total:
      compound_total += each

    yar.append(compound_total)
    print (yar[len(yar)-1], ", ", created[len(created)-1])

    ax1.clear()
    ax1.plot(created, yar, 'bo')
    #plt.plot(np.unique(xar), np.poly1d(np.polyfit(xar, yar, 1))(np.unique(xar)))

ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
数据存储在标准python列表中。我认为列表的长度是相同的,错误表明并非如此

有人能提出解决方案/列表大小不同的原因吗

PS:奇怪的是,程序在抛出错误之前将第一对坐标返回给系统


对于任何愚蠢的事情,我也很抱歉-我不擅长这个

我会尝试打印列表,看看它们有什么不同。也许可以检查一下你是否有一个列表需要换位,所以第一维度是相同的。@pbreach不知道为什么我没有想到这一点!不过还是要谢谢你,结果是在错误的地方出现了一些缩进;)