import matplotlib.pyplot as plt
import numpy as np
from matplotlib import animation
#make the figure
# - set up figure, set up axis(xlim,ylim), set up line as tuple for
animation
fig = plt.figure()
ax = plt.axes(xlim=(-10,50), ylim=(1,50))
line, = ax.plot([],[], lw=2)
#initialization function - display bkgd for each frame
#line has function set data, return it as a tuple
def init():
line.set_data([],[])
return line,
speed = 0.01
#animation function - this is where the physics goes
def animate(i): #i is animation frames
x = np.linspace(0,2,100) #creates set of num evenly spaces from 0,2
y = (x - speed * i)+(((x - speed * i)^2)/2)+(((x - speed * i)^3)/6)
line.set_data(x,y)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,frames=100,
interval=20, blit=True)
plt.show()
I'm trying to approximate "e^x" using the infinite series definition and plot it on a graph.
For whatever reason this code produces a dialog box with a plot for a fraction of a second then ends with an exit code of 1.
I am confused as to why this does not work.