matplotlib.animation 画动态图
程序员文章站
2022-03-09 20:18:02
...
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
def animate(i):
data = open('stock.txt', 'r').read()
lines = data.split('\n')
xs = []
ys = []
for line in lines:
x, y = line.split(',')
xs.append(float(x))
ys.append(float(y))
ax1.clear()
ax1.plot(xs, ys)
plt.xlabel('Data')
plt.xlabel('Price')
plt.title('Focus Degree')
ani = animation.FuncAnimation(fig, animate, interval=300)
plt.show()
下一篇: mac osx vi 高亮显示设置