matplotlib.animation 画动态图

 

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)