diff --git a/Week 6/10 Hyperbolic PDEs.ipynb b/Week 6/10 Hyperbolic PDEs.ipynb index 8994c7e..ea72bb0 100644 --- a/Week 6/10 Hyperbolic PDEs.ipynb +++ b/Week 6/10 Hyperbolic PDEs.ipynb @@ -570,10 +570,31 @@ }, "outputs": [], "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", - "# YOUR CODE HERE\n", - "raise NotImplementedError()" + "# create a figure for the animation\n", + "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" ] }, {