10: Copy template code to task 3
This commit is contained in:
@ -570,10 +570,31 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Animate problem 1 here ...\n",
|
"# use matplotlib's animation package\n",
|
||||||
|
"import matplotlib.pylab as plt\n",
|
||||||
|
"import matplotlib\n",
|
||||||
|
"import matplotlib.animation as animation\n",
|
||||||
|
"# set the animation style to \"jshtml\" (for the use in Jupyter)\n",
|
||||||
|
"matplotlib.rcParams['animation.html'] = 'jshtml'\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# YOUR CODE HERE\n",
|
"# create a figure for the animation\n",
|
||||||
"raise NotImplementedError()"
|
"fig = plt.figure()\n",
|
||||||
|
"plt.grid(True)\n",
|
||||||
|
"plt.xlim( ... ) # fix x limits\n",
|
||||||
|
"plt.ylim( ... ) # fix y limits\n",
|
||||||
|
"\n",
|
||||||
|
"# Create an empty plot object and prevent its showing (we will fill it each frame)\n",
|
||||||
|
"myPlot, = plt.plot([0], [0])\n",
|
||||||
|
"plt.close()\n",
|
||||||
|
"\n",
|
||||||
|
"# This function is called each frame to generate the animation (f is the frame number)\n",
|
||||||
|
"def animate(f): \n",
|
||||||
|
" myPlot.set_data( ... ) # update plot\n",
|
||||||
|
"\n",
|
||||||
|
"# Show the animation\n",
|
||||||
|
"frames = np.arange(1, np.size(t)) # t is the time grid here\n",
|
||||||
|
"myAnimation = animation.FuncAnimation(fig, animate, frames, interval = 20)\n",
|
||||||
|
"myAnimation"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user