Reputation: 53
I tried to use the following code but it just gives me curve line growing and not a point in front of it.
from matplotlib import pyplot as plt
import numpy as np
import mpl_toolkits.mplot3d.axes3d as p3
from matplotlib import animation
fig = plt.figure()
ax = p3.Axes3D(fig)
def gen(n):
phi = 0
while phi < 2*np.pi:
yield np.array([np.cos(phi), np.sin(phi), phi])
phi += 2*np.pi/n
def update(num, data, line):
line.set_data(data[:2, :num])
line.set_3d_properties(data[2, :num])
N = 100
data = np.array(list(gen(N))).T
line, = ax.plot(data[0, 0:1], data[1, 0:1], data[2, 0:1])
# Setting the axes properties
ax.set_xlim3d([-1.0, 1.0])
ax.set_xlabel('X')
ax.set_ylim3d([-1.0, 1.0])
ax.set_ylabel('Y')
ax.set_zlim3d([0.0, 10.0])
ax.set_zlabel('Z')
ani = animation.FuncAnimation(fig, update, N, fargs=(data, line), interval=10000/N, blit=False)
#ani.save('matplot003.gif', writer='imagemagick')
plt.show()
This image is the plot result. What I want is a point marker in front of it that moves but doesn't duplicate! Thanks for taking your time to write the much needed answer.
Upvotes: 0
Views: 523
Reputation: 40667
Do you want a point that moves at the "tip" of you line? If so, a simple way is to use markevery=
in your call to plot
to only have a marker at the last point of the line.
(...)
line, = ax.plot(data[0, 0:1], data[1, 0:1], data[2, 0:1], 'o-', mfc='r', mec='r', markersize=10, markevery=[-1])
(...)
Upvotes: 1