Created
December 24, 2021 15:15
-
-
Save TheTrio/8b3a46278c432dc45635e5b994887be4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from matplotlib.animation import FuncAnimation | |
import random | |
from dataclasses import dataclass | |
@dataclass | |
class Data(): | |
x: list[int] | |
y: list[int] | |
i: int | |
def mutate(data: Data): | |
data.x.append(data.i) | |
data.y.append(random.randint(1, 10)) | |
def animate(i, *fargs): | |
data: Data = fargs[0] | |
plt.cla() | |
plt.plot(data.x, data.y) | |
data.i += 1 | |
mutate(data) | |
if __name__ == "__main__": | |
fig = plt.figure() | |
obj = Data([], [], 0) | |
ani = FuncAnimation(fig, animate, interval=700, fargs=(obj,)) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment