{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "3xXsB4MZ2BIh"
},
"source": [
"# matplotlib tutorial (13) nitta@tsuda.ac.jp\n",
"# Chapter 13: Animation (compatible with Google Colab) \n",
"# JSAnimation\n",
"\n",
"Official document: https://matplotlib.org/api/animation_api.html\n",
"\n",
"JSAnimation has been incorporated into matplotlib since matplotlib 2.1.\n",
"\n",
"JSAnimation realizes animanation by continuously displaying images drawn by matplotlib.pyplot
.\n",
"\n",
"Use the magic '% matplotlib notebook'.\n",
"Note that it is not '% matplotlib inline'.\n",
"\n",
"ArtistAnimation()
passes an array of generated images and displays them all together.\n",
"FuncAnimation()
displays every time an image is generated."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "80B60bU26Stu"
},
"source": [
"## ArtistAnimation : Pass an array of images\n",
"\n",
"### One coordinate system (Axes)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 498
},
"executionInfo": {
"elapsed": 3865,
"status": "ok",
"timestamp": 1657263700989,
"user": {
"displayName": "Yoshihisa Nitta",
"userId": "15888006800030996813"
},
"user_tz": -540
},
"id": "B2pOmTFU_XzF",
"outputId": "998b9999-2d8b-4d38-e364-92a8f71e41f7"
},
"outputs": [
{
"data": {
"application/javascript": [
"/* Put everything inside the global mpl namespace */\n",
"window.mpl = {};\n",
"\n",
"\n",
"mpl.get_websocket_type = function() {\n",
" if (typeof(WebSocket) !== 'undefined') {\n",
" return WebSocket;\n",
" } else if (typeof(MozWebSocket) !== 'undefined') {\n",
" return MozWebSocket;\n",
" } else {\n",
" alert('Your browser does not have WebSocket support. ' +\n",
" 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
" 'Firefox 4 and 5 are also supported but you ' +\n",
" 'have to enable WebSockets in about:config.');\n",
" };\n",
"}\n",
"\n",
"mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
" this.id = figure_id;\n",
"\n",
" this.ws = websocket;\n",
"\n",
" this.supports_binary = (this.ws.binaryType != undefined);\n",
"\n",
" if (!this.supports_binary) {\n",
" var warnings = document.getElementById(\"mpl-warnings\");\n",
" if (warnings) {\n",
" warnings.style.display = 'block';\n",
" warnings.textContent = (\n",
" \"This browser does not support binary websocket messages. \" +\n",
" \"Performance may be slow.\");\n",
" }\n",
" }\n",
"\n",
" this.imageObj = new Image();\n",
"\n",
" this.context = undefined;\n",
" this.message = undefined;\n",
" this.canvas = undefined;\n",
" this.rubberband_canvas = undefined;\n",
" this.rubberband_context = undefined;\n",
" this.format_dropdown = undefined;\n",
"\n",
" this.image_mode = 'full';\n",
"\n",
" this.root = $('