Shunmuga Velayutham
Shunmuga Velayutham

Reputation: 93

Matplotlib 3D scatterplot animation one point at a time

I would like to animate a 3D scatter plot by plotting one point at a time. The effect would be to show a 3D function emerging as the points get populated.

If I use matplotlib FuncAnimation my init should plot one point and then start populating. How to plot a single point in 3D?

Upvotes: 0

Views: 1757

Answers (1)

Shunmuga Velayutham
Shunmuga Velayutham

Reputation: 93

Thanks Andrew let me look into points3d in MayaVi2. In the mean time I tried the following code.

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
plt.ion()

fig = plt.figure(figsize=(12,8))
ax = fig.add_subplot(111, projection='3d')

def fun(x,y):
    return ((x**2 - y**2) * np.exp(-x**2 - y**2)) 

x = y = np.arange(-3.0,3.0, 0.05)
X, Y = np.meshgrid(x,y)
zs = np.array([fun(x,y) for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)

for i in range(len(X)):
    for j in range(len(Y)):
        ax.scatter(X[i][j], Y[i][j], Z[i][j], c='r', marker='o')
        plt.draw()
        plt.pause(0.5)

But the plot is shown only after all the points have been plotted. It is not showing plotting of every point one after another!!

Upvotes: 2

Related Questions