0
爲什麼當新數據通過數據流轉儲到「twitter-out」時,我的數據點會如此顯示?似乎它與動畫有關,因爲當我重新運行文件而沒有在新數據中進行流式傳輸時,它的繪圖就很好。繪圖數據在matplotlib中顯示錯誤
style.use('ggplot')
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
def animate(self):
pullData = open("twitter-out.txt", "r").read()
lines = pullData.split('\n')
xar = []
yar = []
x = 0
y = 0
for l in lines[:]:
x += 1
if "['pos']" in l:
y += 1
elif "['neg']" in l:
y -= 1
xar.append(x)
yar.append(y)
ax1.plot(xar, yar,color='r')
ax1.set_xlabel('Number of Tweets')
ax1.set_ylabel('Sentiment')
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()