{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Parametric" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from matplotlib.animation import PillowWriter\n", "import animatplot as amp\n", "\n", "\n", "def psi(t):\n", " x = t\n", " y = np.sin(t)\n", " return x, y\n", "\n", "\n", "t = np.linspace(0, 2 * np.pi, 25)\n", "x, y = psi(t)\n", "X, Y = amp.util.parametric_line(x, y)\n", "\n", "timeline = amp.Timeline(t, \"s\", 24)\n", "\n", "ax = plt.axes(xlim=[0, 7], ylim=[-1.1, 1.1])\n", "block1 = amp.blocks.Line(X, Y, ax=ax)\n", "# or equivalently\n", "# block1 = amp.blocks.ParametricLine(x, y, ax=ax)\n", "\n", "anim = amp.Animation([block1], timeline)\n", "\n", "# Your standard matplotlib stuff\n", "plt.title(\"Parametric Line\")\n", "plt.xlabel(\"x\")\n", "plt.ylabel(r\"y\")\n", "\n", "# Create Interactive Elements\n", "anim.toggle()\n", "anim.timeline_slider()\n", "\n", "anim.save(\"parametric.gif\", writer=PillowWriter(fps=5))\n", "plt.show()" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. image:: parametric.gif" ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }