Skip to main content

A thin wrapper around the matplotlib FuncAnimation class

Project description

animplotlib

This package acts as a thin wrapper around the matplotlib.animation.FuncAnimation class to simplify animating matplotlib plots.

Installation

pip install animplotlib

User manual

There are two classes which can be called: AnimPlot, for 2-D plots, and AnimPlot3D, for 3-D plots.

AnimPlot

As an example, below is a demonstration of the steps required to make a basic plot of an Euler spiral. An Euler spiral can be obtained by plotting the Fresnel integrals, which can be generated using scipy.special.

Import the necessary libraries and create a matplotlib figure and axes:

import animplotlib as anim
import numpy as np
import matplotlib.pyplot as plt
import scipy.special as sc

fig = plt.figure()
ax = fig.add_subplot(111)

Generate the points being plotted:

x = np.linspace(-10, 10, 2500)
y, z = sc.fresnel(x)

Create two empty matplotlib plots: one to plot the points up to the current most point (i.e. the 'line') and one to plot the current most point:

line, = ax.plot([], [], lw=1)
point, = ax.plot([], [], 'o')

ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)

Call the AnimPlot class and show the plot:

animation = anim.AnimPlot(fig, line, point, y, z, l_num=len(x),
                          plot_speed=5)
plt.show()

l_num is the number of points before the current most point being plotted to line. The default value is set to 10, however in this example it makes sense to set it to the same length as x (i.e. all the points before the current most point are plotted). Similarly, an argument p_num can be passed to determine the number of points being plotted to point. This is set to 1 by default.

Optional arguments:

  • plot_speed (int) : set to 10 by default.
  • l_num (int) : The number of points being plotted to line each frame. By default this is set to 10.
  • p_num (int) : The number of points being plotted to point each frame. By default, this is set to 1, i.e. only the current most point is plotted each frame (the orange point in the gif).
  • save_as (str) : file name to save the animation as a gif in the current working directory.
  • **kwargs : other arguments passable into matplotlib.animation.FuncAnimation (see the docs for more info).

AnimPlot3D

Creating a 3-D animated plot is similar to creating a 2-D plot but with a few additional steps.

import animplotlib as anim
import numpy as np
import matplotlib.pyplot as plt
import scipy.special as sc

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x = np.linspace(-10, 10, 3000)
y, z = sc.fresnel(x)

For 3-D plots, two empty matplotlib plots must be created:

lines, = [ax.plot([], [], [])]
points, = [ax.plot([], [], [], 'o')]

The second plot, points, by default plots the 'ith' point each frame. After that set the x, y and z limits and call the AnimPlot3D class.

ax.set_xlim(-10, 10)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)

animation = anim.AnimPlot3D(fig, ax, [lines], [points], x, y, z, plot_speed=5)
plt.show()

Optional arguments:

  • plot_speed (int) : set to 10 by default.
  • rotation_speed (int) : proportional to plot_speed. Off by default, enabled by setting a value.
  • l_num (int) : The number of points being plotted to lines each frame. By default, all the points up until the current point get plotted.
  • p_num (int) : The number of points being plotted to points each frame. By default, this is set to 1, i.e. only the current most point is plotted each frame (the orange point in the gif).
  • save_as (str) : file name to save the animation as a gif in the current working directory.
  • **kwargs : other arguments passable into matplotlib.animation.FuncAnimation (see the docs for more info).

Both the 2-D and 3-D plots can be customised visually the same way you would a normal matplotlib plot.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

animplotlib-0.2.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

animplotlib-0.2.4-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file animplotlib-0.2.4.tar.gz.

File metadata

  • Download URL: animplotlib-0.2.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for animplotlib-0.2.4.tar.gz
Algorithm Hash digest
SHA256 ef414d8bc98ea23cea7988ad3e3f3a8cb2fbfe2c98abbf3737765101705e0c52
MD5 0c0880131ab67c135c3a0fa4a9503b16
BLAKE2b-256 eb75c6d5d3df815e22107d76aa34a66233fe44f3285cec4fe7b8975a3f669c7f

See more details on using hashes here.

File details

Details for the file animplotlib-0.2.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for animplotlib-0.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2201b58a51d8cf88b05513ba037be6cf4df34ab4e5146d27f720cc28fe287de3
MD5 80e8f52fc3e4c409d1af1b7ed5032d44
BLAKE2b-256 4cdf6878f9d549bbe555c0bfe01f93c2a303decea5f6221354e88ac3a9bf8af6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page