修改
更改了显示的代码,以便其他人可以将其删除并重现错误。可以找到以下代码的数据here,包括代码和生成的动画。
import os
import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation
if __name__ == '__main__':
print "Plotting Clevis LVDT Displacements"
os.chdir(r"F:\BrokenAnimation")
animation_data = np.loadtxt("animation_data.csv", delimiter=",")
time = animation_data[:,0]
L10 = animation_data[:,1]
L11 = animation_data[:,2]
L12 = animation_data[:,3]
def data_gen():
t = data_gen.t
cnt = 0
L10_iter = data_gen.L10_iter
L11_iter = data_gen.L11_iter
L12_iter = data_gen.L12_iter
while cnt < 35000:
cnt+=1
t += 10.0
yield [-10.25, L10_iter.next()], [10.1875, L11_iter.next()],
[L12_iter.next(), -9.0]
data_gen.t = 0
data_gen.L10_iter = iter(np.array(L10))
data_gen.L11_iter = iter(np.array(L11))
data_gen.L12_iter = iter(np.array(L12))
fig, ax = plt.subplots()
scat = ax.scatter([0.0, 0.0, 0.0], [0.0, 0.0, 0.0])
ax.set_xlim(-15, 15)
ax.set_ylim(-10.0, 0.5)
ax.set_ylim(-0.5, 0.5)
ax.grid()
def run(data):
# update the data
x, y, z = data
scat.set_offsets([x, y, z])
return scat,
ani = animation.FuncAnimation(fig, run, data_gen,
blit=True, interval=40, # 40msec? implying 25fps?
)
# This works
plt.show()
# Doesn't really save what I see in plt.show()
ani.save('South_Clevis.mp4') # 435kb file 4 sec long, 25 fps 800x600 887Kbps
我试图绘制下方点位移的时间历程:
y = 0.0处的点是原始位置,动画上下移动点。对于上下文,点表示在35,000秒的时间历程中的LVDT位移,采样率为每秒1。所以每个&#34;秒&#34;情节应该更新。
比特率似乎不是实际做任何事情的关键字。我安装了ffmpeg,它位于Windows路径上。使用basic writer example(但没有行matplotlib.use("Agg")
,因为python抱怨)工作正常并产生可以播放的动画。