I would like:
A plot with a function : f(x,y) -> (x² + y²)/20
A set of points (x, y, f(x,y)) that evolve over time.
To solve this problem I tried to clear the plot and update it at each iteration but I did not manage to do it...
Here's my code:
def parabole(x, y):
return (x * x + y * y)/10
x = np.linspace(-10, 10, 30)
y = np.linspace(-10, 10, 30)
X, Y = np.meshgrid(x, y)
Z = parabole(X, Y)
for swarm in history:
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='jet', edgecolor='none')
for particle in swarm:
ax.scatter(particle[0], particle[1], particle[2])
plt.show()
plt.clf()
history
is a list containing different state of my particle swarm.
My particle swarm is a list of points (x, y, f(x,y))
How do I clear a plot at each iteration of the loop, and then plot the whole thing again in the same figure?