trying to create a simulation for light in form of two perpendicular sine-wave propagating through medium, i.e. propagating through x-axix and oscillating through y and z axis.
Edit-1 : yes, i have gone through this link : 3D animation using matplotlib and the problem solved in above link is different from mine, and i need debugging help for my current code :)
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
import mpl_toolkits.mplot3d.axes3d as p3
plt.style.use('seaborn-pastel')
fig = plt.figure()
ax = p3.Axes3D(fig)
ax.set_xlim(0, 4)
ax.set_ylim(-2, 2)
ax.set_zlim(2, 2)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
line, = ax.plot([], [], [])
def init():
line.set_data([], [], [])
return line,
def animate(i):
x = np.linspace(0, 4, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
z = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y, z)
return line,
anim = FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
plt.show()
# anim.save('sine_wave_3D.gif', writer='imagemagick')
Expected Output : a 3d - animated plot. Result : error: ValueError: too many values to unpack (expected 2)