<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Electric Machinery Fundamentals 5th edition
Chapter 3
Animation
Step1:  Set up the basic conditions
Step2:  First, generate the three component magnetic fields
Step3:  Calculate the combined current vector
Step4:  Calculate neutral current $I_n$
Step5:  Calculate a circle representing the expected maximum value of Itot
Step6:  Generating  the animation
Step7:  The animation above might be a bit "skippy" due to the browser performance trying to cope with the inline animation. 
The solution to a smooth animation is to the animation as a video and embed it right here
<ASSISTANT_TASK:>
Python Code:
%pylab notebook
Explanation: Electric Machinery Fundamentals 5th edition
Chapter 3
Animation: Three-phase currents
(based on Example 3-1)
Calculate the combined currents of a three-phase stator (adapted for 50Hz).
Import the PyLab namespace (provides set of useful commands and constants like $\pi$):
End of explanation
imax = 1                    # Normalize imax to 1
freq = 50                   # [Hz]
w = 2*pi*freq               # [rad/s] angluar velocity
t = linspace(0, 1./50, 100) # 100 values for one period
wt = w*t                    # we are going to use this quite often
Explanation: Set up the basic conditions:
End of explanation
# amplitudes (change them to see effect of non-symmetry):
I_amp = [[1.0], [1.0], [1.0]]
# time variants
I_time = array([sin(wt),
                sin(wt-2*pi/3),
                sin(wt+2*pi/3)])
# vectorial shifts
I_shift = [[cos(0) + 1j*sin(0)],
           [cos(2*pi/3) + 1j*sin(2*pi/3)], 
           [cos(-2*pi/3) + 1j*sin(-2*pi/3)]]
# all combined
I_ph = I_amp * I_time
I = I_ph * I_shift
Explanation: First, generate the three component magnetic fields
End of explanation
Itot = I[0] + I[1] + I[2]
Explanation: Calculate the combined current vector:
End of explanation
# Its amplitude 
In_amp = (I_ph[0] + I_ph[1] + I_ph[2])
# Its angle:
In_ang = angle(Itot)
In = In_amp * exp(1j*In_ang)   # combine to a complex In 
Explanation: Calculate neutral current $I_n$:
End of explanation
circle = 1.5 * (cos(wt) + 1j*sin(wt))
Explanation: Calculate a circle representing the expected maximum value of Itot:
End of explanation
# First set up the figure, the axis, and the plot element we want to animate
from matplotlib import animation
fig = figure()
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 2, 2)
ax1.set_title('Space vectors in motion')
ax1.set_xlabel('Real')
ax1.set_ylabel('Imag')
ax1.set_xlim(-1.6, 1.6)
ax1.set_ylim(-1.6, 1.6)
ax1.set_aspect('equal')
ax2.set_title('Sinusoidal three-phase')
ax2.set_xlabel('wt [rad]')
ax2.set_xlim(0, 2*pi)
ax2.set_ylim(-1.6, 1.6)
# set up the different line colours
la, lb, lc, ltot, ctot, ln, cn = ax1.plot([], [], 'red', 
                                [], [], 'green', 
                                [], [], 'blue', 
                                [], [], 'magenta', 
                                [], [], 'magenta', 
                                [], [], 'y', 
                                [], [], 'y', 
                                lw=2)
# set up the moving dots
da, db, dc, dn = ax2.plot([], [], 'ro',   
                          [], [], 'go',
                          [], [], 'bo', 
                          [], [], 'yo', 
                          lw=2)
tight_layout()  # sometimes useful when sub-plots get a bit crowded
# initialization function: plot the background of each frame
def init():
    ax1.plot(real(circle), imag(circle), 'black');
    ax2.plot(wt, I_ph[0,], 'red',
             wt, I_ph[1,], 'green',
             wt, I_ph[2,], 'blue',
             wt, In_amp, 'y',
             lw=1);
    return
# animation function.  This is called sequentially
def animate(simData):
    i = simData - 1 # python index starts at 0 
    re = [real(I[0,i]), real(I[1,i]), real(I[2,i])]
    im = [imag(I[0,i]), imag(I[1,i]), imag(I[2,i])]
    ren = real(In[i])
    imn = imag(In[i])
    la.set_data([0, re[0]], 
                [0, im[0]])
    lb.set_data([0, re[1]], 
                [0, im[1]])
    lc.set_data([0, re[2]],
                [0, im[2]])
    ltot.set_data([0, real(Itot[i])], [0, imag(Itot[i])])
    ctot.set_data(real(Itot[:i+1]),imag(Itot[:i+1]))
    ln.set_data([0, real(In[i])], [0, imag(In[i])])
    cn.set_data(real(In[:i]), imag(In[:i]))
    da.set_data(wt[i], I_ph[0,i])
    db.set_data(wt[i], I_ph[1,i])
    dc.set_data(wt[i], I_ph[2,i])
    dn.set_data(wt[i], In_amp[i])
    return la, lb, lc, ltot, da, db, dc
    
# call the animator:  
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=100, interval=50)   
Explanation: Generating  the animation:
End of explanation
from IPython.display import HTML
HTML(anim.to_html5_video())
Explanation: The animation above might be a bit "skippy" due to the browser performance trying to cope with the inline animation. 
The solution to a smooth animation is to the animation as a video and embed it right here:
End of explanation
<END_TASK>