0

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)

Transwert
  • 83
  • 1
  • 10
  • Did you read through [3d-animation-using-matplotlib](https://stackoverflow.com/questions/38118598/3d-animation-using-matplotlib)? – ImportanceOfBeingErnest Oct 30 '19 at 16:21
  • @ImportanceOfBeingErnesti read through it, but i tried to do this i much simpler manner, ( with lesser code ), but ended up with error. so now i am trying to solve error in this code – Transwert Oct 30 '19 at 16:38
  • The reason the other answer did not use a simpler code is precisely that it doesn't work. So having the choice between a simple code which errors out and a more complicated code which works fine... my priorities would be clear in such case. ;-) – ImportanceOfBeingErnest Oct 30 '19 at 16:40
  • @ImportanceOfBeingErnest don't get me wrong, but sometimes it gives you different feels of finding and solving problems in your approach than using easy way to find other solution :) please help me with this one [ and honestly not able to adapt to link, according to my problem :( ] – Transwert Oct 30 '19 at 17:33
  • The problem is that `set_data` accepts two datasets, x and y; while you provide three. As said, see the linked question for how to set the data. – ImportanceOfBeingErnest Oct 30 '19 at 18:59

0 Answers0