I am attempting to build a scatterplot and am stumped on the animations. Ultimately, I want there to be >1000 points, plotted at a random, normal distribution around (0,0). Each point should then rotate either clockwise or counter-clockwise around (0,0) at varying speeds.
I was trying to do this with a loop function that would randomize movement, but it is extremely slow, and as of yet I have been unable to make more than one point move:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = 4,3
from matplotlib.animation import FuncAnimation
from math import sqrt, exp
from matplotlib.animation import FuncAnimation, PillowWriter
fig, ax = plt.subplots()
# set the axes limits
ax.axis([-2.5,2.5,-2.5,2.5])
# set equal aspect such that the circle is not shown as ellipse
ax.set_aspect("equal")
# create a point in the axes
for i in range(0,6):
x = np.random.normal()
y = np.random.normal()
r = np.sqrt(x*x+y*y)
def circle(phi):
return np.array([r*np.cos(phi), r*np.sin(phi)])
point, = ax.plot(x,y, marker="o")
ani = FuncAnimation(fig, update, interval=10, blit=True, repeat=True,
frames=np.linspace(0,2*np.pi,360, endpoint=False))
plt.show()
writer = PillowWriter(fps=25)
ani.save(r'[path --> .gif]', writer=writer)
How can I fix this code?