欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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()


 

相关标签: Python