Animations

This page lists the different animations that can be applied to plot objects. All animations share the following parameters:

  • duration: the number of frames the animation runs from.

  • delay(optional): the number of frames after what the animation starts playing.

  • easing(optional): the easing used for this animation (See Easings). If None, a linear easing is applied.

Once animations have been set on plot objects, they have to be rendered via Timeline.animate(plot_objs) (See Timeline).

Animations of plot objects

Translate

Animation.translate(start_pos, end_pos, duration, delay=0, easing=None, persistent=True)[source]

Move a plot object from one position to another.

Parameters:
  • start_pos (array-like) – where the translation starts, relative to the current center of the plot object.

  • end_pos (array-like) – where the translation ends, relative to the current center of the plot object.

  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

  • persistent (bool, default=True) – if True, the plot object will continue to be plotted after its last animation has played.

import diplotocus as dpl

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))

p = dpl.plot(x=x,y=y)
p.translate(start_pos=(0,0),end_pos=(1,1),duration=60)

tl.animate(p)
tl.save_video('../_static/anim_translate.mp4')

Saved video ../_static/anim_translate.mp4

Rotate

Animation.rotate(start_angle, end_angle, duration, center=None, delay=0, easing=None, persistent=True)[source]

Rotate a plot object from one angle to another.

Parameters:
  • start_angle (float) – the starting angle of the rotation in radians.

  • end_angle (float) – the ending angle of the rotation in radians.

  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

  • persistent (bool, default=True) – if True, the plot object will continue to be plotted after its last animation has played.

import diplotocus as dpl

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))

p = dpl.plot(x=x,y=y)
p.rotate(start_angle=20,end_angle=110,duration=60)

tl.animate(p)
tl.save_video('../_static/anim_rotate.mp4')

Saved video ../_static/anim_rotate.mp4

Scale

Animation.scale(start_scale, end_scale, duration, center=None, delay=0, easing=None, persistent=True)[source]

Scale a plot object from one size to another.

Parameters:
  • start_scale (float or tuple[float, float]) – the starting scale of the plot object.

  • end_scale (float or tuple[float, float]) – the ending scale of the plot object.

  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

  • persistent (bool, default=True) – if True, the plot object will continue to be plotted after its last animation has played.

  • values (You can either pass scalar)

  • scaled (in which case the plot object will be uniformly)

  • scales. (or a 2-tuple for independent X and Y)

import diplotocus as dpl

x = [-1,1,0,-1]
y = [-1,-1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))

p = dpl.plot(x=x,y=y)
p.scale(start_scale=(0,1),end_scale=(2,0),duration=60)

tl.animate(p)
tl.save_video('../_static/anim_scale.mp4')

Saved video ../_static/anim_scale.mp4

Tween

Animation.tween(property, start, end, duration, delay=0, easing=None, persistent=True)[source]

Animate a change in a property of the plot object.

Parameters:
  • property (str) – the name of the property to animate.

  • start (any) – the starting value of the property.

  • end (any) – the ending value of the property.

  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

Animation.tweens(properties, starts, ends, duration, delay=0, easing=None, persistent=True)[source]

Animate multiple properties at once.

Parameters:
  • properties (list[str]) – a list of the names of the properties to animate.

  • starts (list[Any]) – the starting values of the properties.

  • ends (list[Any]) – the ending values of the properties.

  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

Note

show() is a shorthand animation that fades in plot objects. It is equivalent to tween('alpha',0,1).

hide() is a shorthand animation that fades out plot objects. It is equivalent to tween('alpha',1,0).

import diplotocus as dpl

x = [-1,1,0,-1]
y = [-1,-1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))

p = dpl.plot(x=x,y=y)
p.tween(property='c',start='red',end='green',duration=60)

tl.animate(p)
tl.save_video('../_static/anim_tween.mp4')

Saved video ../_static/anim_tween.mp4

Morph

Animation.morph(new_x, new_y, duration, delay=0, easing=None, persistent=True)[source]

Morph between the base dataset and a new dataset.

Parameters:
  • new_x (array-like or float) – the x data points to morph to.

  • new_y (array-like or float) – the y data points to morph to.

  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

  • persistent (bool, default=True) – if True, the plot object will continue to be plotted after its last animation has played.

  • hist()) (For plot objects that take 1D datasets (e.g.)

  • new_x. (morph() only accepts)

import diplotocus as dpl
import numpy as np

x = np.linspace(0,2*np.pi,60)
y = np.cos(x)

tl = dpl.Timeline(xlim=(-1,7),ylim=(-2,2))

p = dpl.plot(x=x,y=y)

x2 = (np.cos(x)+1)*2
y2 = np.sin(x)
p.morph(new_x=x2,new_y=y2,duration=60)

tl.animate(p)
tl.save_video('../_static/anim_morph.mp4')

Saved video ../_static/anim_morph.mp4

Draw

Animation.draw(duration, reverse=False, delay=0, easing=None, persistent=True)[source]

Animate the plot object by sequentially adding more points of the dataset.

Parameters:
  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

  • reverse (bool, default=False) – if True, removes points sequentially instead of adding points.

  • persistent (bool, default=True) – if True, the plot object will continue to be plotted after its last animation has played.

import diplotocus as dpl
import numpy as np

x = np.linspace(0,2*np.pi,60)
y = np.cos(x)

tl = dpl.Timeline(xlim=(-1,7),ylim=(-2,2))

p = dpl.plot(x=x,y=y)
p.draw(duration=60)

tl.animate(p)
tl.save_video('../_static/anim_draw.mp4')

Saved video ../_static/anim_draw.mp4

Sequence

Animation.sequence(duration, delay=0, easing=None, persistent=True)[source]

Plot one datapoint or row of the dataset per frame.

Parameters:
  • duration (float) – the number of frames the animation runs from.

  • delay (float, default=0) – the number of frames after what the animation starts playing.

  • easing (callable, optional) – the easing used for this animation. If None, a linear easing is applied.

  • persistent (bool, default=True) – if True, the plot object will continue to be plotted after its last animation has played.

  • 1-dimensional (If the dataset is)

  • frame (this plots a single datapoint per)

  • 2D (if)

  • frame-by-frame. (it will plot one row per frame. This animation can be used if you have a predefined list of datapoints you want to animate)

import diplotocus as dpl
import numpy as np

x = np.linspace(0, 2*np.pi, 60)
x_rev = x[::-1]
xs = np.column_stack((x, x_rev))
ys = np.column_stack((np.cos(x), np.sin(x_rev)))

tl = dpl.Timeline(xlim=(-1,7),ylim=(-2,2))

p = dpl.plot(x=xs,y=ys,lw=0,marker='+',ms=10)
p.sequence(duration=50)

tl.animate(p)
tl.save_video('../_static/anim_sequence.mp4')

Saved video ../_static/anim_sequence.mp4

Animations of figures and axes

Axis zoom

animations.axis_zoom(duration, delay=0, easing=None, axis=None, *args, **kwargs)[source]

Zooms into the axis given a zoom value.

Parameters:
  • zoom (float) – Zoom level

  • duration (float) – Duration of the animation

  • delay (float, default=0) – Delay before starting

  • easing (callable, optional) – Easing function

  • axis (matplotlib.axes.Axes, optional) – Axis to plot on

Example

Zoom 2 times in 100 frames:
>>> axis_zoom(zoom=2,duration=100)
import diplotocus as dpl

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))
tl.main_axis.plot(x,y)

a = dpl.axis_zoom(zoom=2,duration=60)

tl.animate(a)
tl.save_video('../_static/axis_zoom.mp4')

Saved video ../_static/axis_zoom.mp4

Axis limits

animations.axis_limits(xlim=None, ylim=None, delay=0, easing=None, axis=None, *args, **kwargs)[source]

Reframe axis to the given limits (on the x-axis, y-axis or both depending on passed arguments)

Parameters:
  • xlim (array-like, default=None) – Target limits of the x-axis

  • ylim (array-like, default=None) – Target limits of the y-axis

  • duration (float) – Duration of the animation

  • delay (float, default=0) – Delay before starting

  • easing (callable, optional) – Easing function

  • axis (matplotlib.axes.Axes, optional) – Axis to plot on

Example

Reframe x-axis to limits [0-2] in 100 frames:
>>> axis_limits(xlim=(0,2),duration=100)
import diplotocus as dpl

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))
tl.main_axis.plot(x,y)

a = dpl.axis_limits(xlim=(-5,5),ylim=(-1,1),duration=60)

tl.animate(a)
tl.save_video('../_static/axis_limits.mp4')

Saved video ../_static/axis_limits.mp4

Axis move

animations.axis_move(duration, start_pos=None, delay=0, easing=None, axis=None, *args, **kwargs)[source]

Move the center of the axis to a given position.

Parameters:
  • pos (array-like) – Target center position

  • duration (float) – Duration of the animation

  • delay (float, default=0) – Delay before starting

  • easing (callable, optional) – Easing function

  • axis (matplotlib.axes.Axes, optional) – Axis to plot on

Example

Recenter the axis to (-1,-1) in 100 frames:
>>> axis_move(pos=(-1,-1),duration=100)
import diplotocus as dpl

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))
tl.main_axis.plot(x,y)

a = dpl.axis_move(end_pos=(1,1),duration=60)

tl.animate(a)
tl.save_video('../_static/axis_move.mp4')

Saved video ../_static/axis_move.mp4

Axis alpha

animations.axis_alpha(end_alpha, duration, delay=0, alpha_objs=True, easing=None, axis=None, *args, **kwargs)[source]

Change the opacity of the axis.

Parameters:
  • start_alpha (float) – Initial alpha value

  • end_alpha (float) – Final alpha value

  • duration (float) – Duration of the animation

  • delay (float, default=0) – Delay before starting

  • easing (callable, optional) – Easing function

  • axis (matplotlib.axes.Axes, optional) – Axis to plot on

Example

Make the axis appear in 100 frames
>>> axis_alpha(start_alpha=0,end_alpha=1,duration=100)
import diplotocus as dpl

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

tl = dpl.Timeline(xlim=(-2.5,2.5),ylim=(-2,2))
tl.main_axis.plot(x,y)

a = dpl.axis_alpha(start_alpha=0,end_alpha=1,duration=50)

tl.animate(a)
tl.save_video('../_static/axis_alpha.mp4')

Saved video ../_static/axis_alpha.mp4

Figure width ratio

animations.fig_width_ratio(end_widths, duration, delay=0, easing=None, axis=None, *args, **kwargs)[source]

Resize subplots’ widths.

Parameters:
  • start_widths (array-like) – Starting width ratios

  • end_widths (array-like) – End width ratios

  • duration (float) – Duration of the animation

  • delay (float, default=0) – Delay before starting

  • easing (callable, optional) – Easing function

  • axis (matplotlib.axes.Axes, optional) – Axis to plot on

Example

Resize 2 subplots from equal widths to a ratio of 2:1 in 100 frames:
>>> fig_width_ratio(start_widths=(1,1),end_widths=(1,2),duration=100)
import diplotocus as dpl
import matplotlib.pyplot as plt

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

fig,ax = plt.subplots(1,2,figsize=(10,5))
ax[0].plot(x,y)
ax[1].plot(x,y)
tl = dpl.Timeline(fig=fig)

a = dpl.fig_width_ratio(start_widths=(1,0),end_widths=(0,1),duration=60)

tl.animate(a)
tl.save_video('../_static/fig_width_ratio.mp4')

Saved video ../_static/fig_width_ratio.mp4

Figure height ratio

animations.fig_height_ratio(end_heights, duration, delay=0, easing=None, axis=None, *args, **kwargs)[source]

Resize subplots’ heights.

Parameters:
  • start_heights (array-like) – Starting height ratios

  • end_heights (array-like) – End height ratios

  • duration (float) – Duration of the animation

  • delay (float, default=0) – Delay before starting

  • easing (callable, optional) – Easing function

  • axis (matplotlib.axes.Axes, optional) – Axis to plot on

Example

Resize 2 subplots from equal heights to a ratio of 2:1 in 100 frames:
>>> fig_width_ratio(start_heights=(1,1),end_heights=(1,2),duration=100)
import diplotocus as dpl
import matplotlib.pyplot as plt

x = [-1,1,1,-1,-1]
y = [-1,-1,1,1,-1]

fig,ax = plt.subplots(2,1,figsize=(7,7))
ax[0].plot(x,y)
ax[1].plot(x,y)
tl = dpl.Timeline(fig=fig)

a = dpl.fig_height_ratio(start_heights=(1,0),end_heights=(0,1),duration=60)

tl.animate(a)
tl.save_video('../_static/fig_height_ratio.mp4')

Saved video ../_static/fig_height_ratio.mp4