{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Scatter" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib qt\n", "import numpy as np\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import animatplot as amp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sample data:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "x = np.linspace(0, 10, 100)\n", "t = np.linspace(0, 2 * np.pi, 100)\n", "\n", "X, T = np.meshgrid(x, t)\n", "\n", "Y1 = np.sin(X + T)\n", "Y2 = np.sin(X + T + np.pi / 2)\n", "\n", "Sizes = 20 * np.cos(X - 5 * T) ** 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Producing the animation:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "timeline = amp.Timeline(T, fps=10)\n", "block1 = amp.blocks.Scatter(X, Y1, Sizes, c=\"r\")\n", "block2 = amp.blocks.Scatter(X, Y2, 1, c=\"b\")\n", "anim = amp.Animation([block1, block2], timeline)\n", "\n", "anim.controls()\n", "anim.save_gif(\"scatter\") # save animation for the docs\n", "plt.show()" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. image:: scatter.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 }