{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "commercial-billion", "metadata": {}, "outputs": [], "source": [ "# for lecture use notebook\n", "%matplotlib inline\n", "\n", "# set up view\n", "import matplotlib.animation as animation\n", "import matplotlib as mp\n", "mp.rcParams['animation.html'] = 'jshtml'\n", "\n", "qr_setting = None\n", "qrviz_setting = 'save'\n", "#\n", "%config InlineBackend.figure_format='retina'\n", "# import libraries\n", "import numpy as np\n", "import matplotlib as mpf\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import laUtilities as ut\n", "import slideUtilities as sl\n", "import demoUtilities as dm\n", "import pandas as pd\n", "from importlib import reload\n", "from datetime import datetime\n", "from IPython.display import Image\n", "from IPython.display import display_html\n", "from IPython.display import display\n", "from IPython.display import Math\n", "from IPython.display import Latex\n", "from IPython.display import HTML;" ] }, { "cell_type": "markdown", "id": "aware-inventory", "metadata": {}, "source": [ "# Explanation\n", "\n", "These are stored and run from this notebook because doing it in the lecture slides notebook introduces irritating artifacts: it does not seem to be possible to create the animation and display it without also displaying the still image produced in the last animation frame!\n", "\n", "## Update January 2022: \n", "\n", "After searching stack exchange again I discovered the trick of closing the figure in order to suppress\n", "the still image. This notebook is updated to show the technique,\n", "but I moved all the code back into the main L17 notebook, so this notebook\n", "is no longer needd." ] }, { "cell_type": "code", "execution_count": 18, "id": "qualified-librarian", "metadata": {}, "outputs": [], "source": [ "# we are putting x into a list so that it can be read inside the\n", "# animate() closure. Currently can only read env variables in a closure\n", "\n", "# this is the routine that will be called on each timestep\n", "def animate(i):\n", " newx = A @ x[0]\n", " x[0] = newx\n", " xvals.append(x[0][0])\n", " yvals.append(x[0][1])\n", " lines[0].set_data(xvals,yvals)" ] }, { "cell_type": "code", "execution_count": 24, "id": "angry-administration", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "