Skip to content

Instantly share code, notes, and snippets.

@TheTrio
Created December 24, 2021 15:15
Show Gist options
  • Save TheTrio/8b3a46278c432dc45635e5b994887be4 to your computer and use it in GitHub Desktop.
Save TheTrio/8b3a46278c432dc45635e5b994887be4 to your computer and use it in GitHub Desktop.
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