Python Forum
Error when animating 3D plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when animating 3D plot
#1
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.

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()
Reply


Messages In This Thread
Error when animating 3D plot - by Tee - Jul-03-2023, 04:34 AM
RE: Error when animating 3D plot - by deanhystad - Jul-03-2023, 12:02 PM
RE: Error when animating 3D plot - by Tee - Jul-03-2023, 12:32 PM
RE: Error when animating 3D plot - by deanhystad - Jul-03-2023, 12:45 PM
RE: Error when animating 3D plot - by Tee - Jul-03-2023, 08:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Value Error when Trying to Plot Filtered Waveforms mkohler 1 167 May-09-2024, 05:33 PM
Last Post: deanhystad
  Likert survey data plot error Andrzej_Andrzej 6 1,525 Jul-16-2023, 10:11 PM
Last Post: deanhystad
  How to plot intraday data of several days in one plot mistermister 3 2,978 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,962 Jun-12-2019, 03:31 PM
Last Post: SriMekala
  scatter plot error - possibly data type - TypeError: nan is not a string chudson 1 6,579 Mar-24-2019, 11:48 AM
Last Post: chudson
  Animating Random Walk Excelsiscelia 2 5,273 Nov-24-2018, 08:53 AM
Last Post: Excelsiscelia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020