Skip to content

Instantly share code, notes, and snippets.

@anupam-io
Created February 5, 2021 11:07
Show Gist options
  • Save anupam-io/5526cbda42199ae74412fa663d8d30bc to your computer and use it in GitHub Desktop.
Save anupam-io/5526cbda42199ae74412fa663d8d30bc to your computer and use it in GitHub Desktop.
Live animation from X and Y values in Python
import matplotlib.pyplot as plt
import numpy as np
import time
from random import randint
n = 10
x = []
y = []
plt.ion()
fig = plt.figure(figsize=(8, 6))
for _ in range(n*n):
# Here you can update values of X and Y
x = [randint(1, n) for i in range(n)]
y = [randint(1, n) for i in range(n)]
plt.cla()
plt.scatter(x, y)
fig.canvas.draw()
fig.canvas.flush_events()
time.sleep(0.3) # Waiting for some time to start the next iteration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment