Jul-03-2023, 04:34 AM
I am trying to animate a 3D plot. I am getting an error and I can't figure out why.
The program runs without any issues when the dot1 plot is not included. But I get the following error when I include dot1.
The program runs without any issues when the dot1 plot is not included. But I get the following error when I include dot1.
Error:File "/Users/Tee/anaconda3/lib/python3.10/site-packages/mpl_toolkits/mplot3d/art3d.py", line 175, in set_3d_properties
zs = np.broadcast_to(zs, len(xs))
TypeError: object of type 'numpy.float64' has no len()import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
x = np.sort(10 + np.random.rand(1,100)*5)
y = np.sort(10 + np.random.rand(1,100)*2)
z = np.sort(20 + np.random.rand(1,100)*10)
def animate(num,x,y, z, line1,dot1):
line1.set_data(np.array([x[0][:num], y[0][:num]]))
line1.set_3d_properties(z[0][:num])
dot1.set_data(np.array([x[0][num], y[0][num]]))
dot1.set_3d_properties(z[0][num])
return line1, dot1
fig = plt.figure(7)
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(10, 15)
ax.set_ylim(10, 12)
ax.set_zlim(20, 30)
line1, = ax.plot([],[],[], c='b')
dot1, = ax.plot(x[0][0], y[0][0], z[0][0], linestyle="", marker="o", c='r', linewidth=1)
N = x.size
anim = animation.FuncAnimation(fig, animate, N, fargs=(x,y, z, line1,dot1),interval = 10, blit=False)
# Show the plot!
plt.show()
