Welcome to mplEasyAnimate’s documentation!

An easy way to make matplotib animations! All of the functionality is contained in the animate.py file. The rest of the files are just examples.

class mplEasyAnimate.animate.animation(filename: str, size: Tuple[int, int] = None, pbar: bool = False, mbs: int = 16, dpi: int = 150, init_frame: matplotlib.figure.Figure = None, init_ax: matplotlib.axes._subplots.AxesSubplot = None, fps: int = 5, interactive: bool = False, autoSmooth: bool = False, smoothingFrames: int = 5, saveFinalFrame: int = False, smoothingTime: float = None, smoothingFunction: Callable = None)

Animation class. This class requires will take in a matplotib figure object and add it to an imageio open video file.

Attributes:

filenamestr

Filename to animation will be written to

sizeTuple[int]

X, Y dimensions of image (x, y)

pbarbool

Flag controlling use of a tqdm progress bar

dpiint

image dpi (dots per inch)

Examples:

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from animate import animation
>>> fig, ax = plt.subplots()
>>> x = np.linspace(0, 2*np.pi, 100)
>>> line, = ax.plot(x, np.sin(x))
>>> anim = animation('test.mp4', size=(500, 500), pbar=True)
>>> for i in range(100):
>>>     line.set_ydata(np.sin(x + i/10.0))
>>>     anim.add_frame(fig)
>>> anim.close()

Constructs all the necessary attributes for the animation object. If init_frame and init_ax are provided then the animation will be drawn on top of the init_frame. This can be used to speed up the animation process. If the matplotlib enviroment is interactive then that will be recorded and restored when the animation is closed.

Parameters:

filenamestr

Filename to write animation too

sizetuple[int], default=None

X, Y dimensions of image (x, y)

pbarbool, default=False

Use tqdm progress bar

mbsint, default=16

image macro_block_size to use

dpiint, default=150

image dpi

init_framematplotlib.figure.Figure, default=None

canvas to draw on, use to speed up animation

init_axmatplotlib.axes._subplots.AxesSubplot, default=None

axes to go with init_frame

fpsint, default=5

frames per second to draw animation at

ineractivebool, default=False

disable matplotlib interactive mode on animation start

autoSmoothbool, default=False

Smooth transitions between frames by adding intermediate frames

smoothingFramesint, default=5

Number of frames to add between each frame

saveFinalFramebool, default=False

Save the final frame of the animation to a png file called finalFrame.png

smoothingTimefloat, default=None

Time in seconds to smooth over. If this is provided then smoothingFrames will be ignored.

smoothingFunctionCallable, default=None

Function to use to smooth frames. This function should take two frames along with a frame index and the total number of frames to be smoothed over and return a new frame of the same size. If this is not provided and autoSmooth is turned on then a linear interpolation between the two frames will be used (cross fade). The function should return a numpy array of the same size as the input frames and as type np.uint8.

add_frame(frame: matplotlib.figure.Figure, facecolor: str = 'white')

User facing call to add a single frame.

Parameters:
  • frame (matplotlib.figure) – Matplotlib figure

  • facecolor (str, default='white') – Background color of animation

add_frames(frameList: list[matplotlib.figure.Figure], facecolor: str = 'white')

User facing call to add list of frames.

Parameters:
  • frameList (List[matplotlib.figure]) – List of matplotlib figures

  • facecolor (str, default='white') – Background color of animation

close()

Safe close of animation.