matplotlib

Previous topic

animation example code: rain.py

Next topic

animation example code: simple_3danim.py

This Page

animation example code: random_data.pyΒΆ

[source code]

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)


def update(data):
    line.set_ydata(data)
    return line,


def data_gen():
    while True:
        yield np.random.rand(10)

ani = animation.FuncAnimation(fig, update, data_gen, interval=100)
plt.show()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)