【发布时间】:2019-01-21 05:58:37
【问题描述】:
我正在尝试让animation 在matplotlib 工作。我以前有这个code 工作,但现在我返回一个错误。我不确定更新是否导致了这种情况?
code 在下方。这是以前的工作。但现在它返回一个错误:
raise TypeError("invalid type comparison")
TypeError: invalid type comparison
例子:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
import pandas as pd
d = ({
'Time' : [1,2,3,4,5,6,7,8,9,10],
})
df = pd.DataFrame(data = d)
fig, ax = plt.subplots(figsize = (10,6))
#Event Table
Events_table = plt.table(cellText= [[''],[''],[''],[''],['']],
colWidths = [1],
rowLabels=['Time','1','2','3','4'],
colLabels=['Events'],
bbox = [0.124, 0.75, 0.236, 0.22])
Frame_number = df['Time']
label = plt.text(-180, 50, Frame_number, fontsize = 8, ha = 'center')
def animate(i) :
label.set_text(Frame_number[i+1])
ani = animation.FuncAnimation(fig, animate, np.arange(0,10),# init_func = init,
interval = 100, blit = False)
plt.draw()
【问题讨论】:
-
试试
label = plt.text(-180, 50, str(Frame_number[0]), fontsize = 8, ha = 'center')和label.set_text(str(Frame_number[i+1]))。 -
谢谢@Thomas Kuhn
标签: python pandas matplotlib animation