【发布时间】:2015-10-13 17:56:15
【问题描述】:
我正在使用 Panda 和 matplotlib 在 Python 中绘制图形。 我想要一个实时更新的间隙。这是我的代码:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import numpy as np
import MySQLdb
import pandas
def animate():
conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="sentiment_index", use_unicode=True, charset="utf8")
c = conn.cursor()
query = """ SELECT t_date , score FROM mytable where t_date BETWEEN Date_SUB(NOW(), Interval 2 DAY) AND NOW()"""
c.execute(query)
rows=c.fetchall()
df = pandas.read_sql(query, conn, index_col=['t_date'])
df.plot()
plt.show()
animate()
我考虑过使用 FuncAnimation,但没有得到正确的结果。有什么帮助吗?
【问题讨论】:
标签: python mysql python-2.7 pandas matplotlib