Animation support

class Animate(ax=None, dim=None, projection='ortho', labels=('X', 'Y', 'Z'), **kwargs)[source]

Bases: object

Animate objects for matplotlib 3d

An instance of this class behaves like an Axes3D and supports proxies for

  • plot

  • quiver

  • text

  • scatter

which renders them and also places corresponding objects into a display list. These objects are Line, Quiver and Text. Only these primitives will be animated.

The objects are all drawn relative to the origin, and will be transformed according to the transform that is being animated.

Example:

anim = animate.Animate(dims=[0,2]) # set up the 3D axes
anim.trplot(T, frame='A', color='green')  # draw the frame
anim.run(repeat=True)  # animate it
__init__(ax=None, dim=None, projection='ortho', labels=('X', 'Y', 'Z'), **kwargs)[source]

Construct an Animate object

Parameters
  • ax (Axes3D reference) – the axes to plot into, defaults to current axes

  • dim (array_like(6) or array_like(2)) – dimension of plot volume as [xmin, xmax, ymin, ymax, zmin, zmax]. If dims is [min, max] those limits are applied to the x-, y- and z-axes.

  • projection (str) – 3D projection: ortho [default] or persp

  • labels (3-tuple of strings) – labels for the axes, defaults to X, Y and Z

Will setup to plot into an existing or a new Axes3D instance.

__repr__()[source]

Human readable version of the display list

Parameters

self (Animate) – the animation

Returns

readable version of the display list

Return type

str

__str__()[source]

Return str(self).

Return type

str

artists()[source]

List of artists that need to be updated

Parameters

self (Animate) – the animation

Returns

list of artists

Return type

list

plot(x, y, z, *args, **kwargs)[source]

Plot a polyline

Parameters
  • x (array_like) – list of x-coordinates

  • y (array_like) – list of y-coordinates

  • z (array_like) – list of z-coordinates

Other arguments as accepted by the matplotlib method.

All arrays must have the same length.

Seealso

matplotlib.pyplot.plot()

quiver(x, y, z, u, v, w, *args, **kwargs)[source]

Plot a quiver

Parameters
  • x (array_like) – list of base x-coordinates

  • y (array_like) – list of base y-coordinates

  • z (array_like) – list of base z-coordinates

  • u (array_like) – list of vector x-coordinates

  • v (array_like) – list of vector y-coordinates

  • w (array_like) – list of vector z-coordinates

Draws a series of arrows, the bases defined by corresponding elements of (x,y,z) and the vector has components defined by corresponding elements of (u,v,w).

Other arguments as accepted by the matplotlib method.

Seealso

matplotlib.pyplot.quiver()

run(movie=None, axes=None, repeat=False, interval=50, nframes=100, wait=False, **kwargs)[source]

Run the animation

Parameters
  • axes (Axes3D reference) – the axes to plot into, defaults to current axes

  • repeat (bool) – animate in endless loop [default False]

  • nframes (int) – number of steps in the animation [default 100]

  • interval (int) – number of milliseconds between frames [default 50]

  • movie (str, bool) – name of file to write MP4 movie into, or True

  • wait (bool) – wait until animation is complete, default False

Animates a 3D coordinate frame moving from the world frame to a frame represented by the SO(3) or SE(3) matrix to the current axes.

Note

  • the movie option requires the ffmpeg package to be installed: conda install -c conda-forge ffmpeg

  • if movie=True then return an HTML5 video which can be displayed in a notebook using HTML()

  • invokes the draw() method of every object in the display list

scatter(xs, ys, zs, s=0, **kwargs)[source]
set_proj_type(proj_type)[source]
set_xlabel(*args, **kwargs)[source]
set_xlim(*args, **kwargs)[source]
set_ylabel(*args, **kwargs)[source]
set_ylim(*args, **kwargs)[source]
set_zlabel(*args, **kwargs)[source]
set_zlim(*args, **kwargs)[source]
text(x, y, z, *args, **kwargs)[source]

Plot text

Parameters
  • x (float) – x-coordinate

  • y (float) – float

  • z (float) – z-coordinate

  • kwargs – Other arguments as accepted by the matplotlib method.

.text(x, y, z, s) display the string s at coordinate (x, y, z).

Seealso

text()

trplot(end, start=None, **kwargs)[source]

Define the transform to animate

Parameters
  • end (ndarray(4,4) or ndarray(3,3)) – the final pose SE(3) or SO(3) to display as a coordinate frame

  • start (ndarray(4,4) or ndarray(3,3)) – the initial pose SE(3) or SO(3) to display as a coordinate frame, defaults to null

  • start – an

Is polymorphic with base.trplot and accepts the same parameters. This sets up the animation but doesn’t execute it.

Seealso

run()

__dict__ = mappingproxy({'__module__': 'spatialmath.base.animate', '__doc__': "\n    Animate objects for matplotlib 3d\n\n    An instance of this class behaves like an Axes3D and supports proxies for\n\n    - ``plot``\n    - ``quiver``\n    - ``text``\n    - ``scatter``\n\n    which renders them and also places corresponding objects into a display\n    list. These objects are ``Line``, ``Quiver`` and ``Text``.  Only these\n    primitives will be animated.\n\n    The objects are all drawn relative to the origin, and will be transformed\n    according to the transform that is being animated.\n\n    Example::\n\n        anim = animate.Animate(dims=[0,2]) # set up the 3D axes\n        anim.trplot(T, frame='A', color='green')  # draw the frame\n        anim.run(repeat=True)  # animate it\n    ", '__init__': <function Animate.__init__>, 'trplot': <function Animate.trplot>, 'set_proj_type': <function Animate.set_proj_type>, 'run': <function Animate.run>, '__repr__': <function Animate.__repr__>, '__str__': <function Animate.__str__>, 'artists': <function Animate.artists>, '_draw': <function Animate._draw>, '_Line': <class 'spatialmath.base.animate.Animate._Line'>, 'plot': <function Animate.plot>, '_Quiver': <class 'spatialmath.base.animate.Animate._Quiver'>, 'quiver': <function Animate.quiver>, '_Text': <class 'spatialmath.base.animate.Animate._Text'>, 'text': <function Animate.text>, 'scatter': <function Animate.scatter>, 'set_xlim': <function Animate.set_xlim>, 'set_ylim': <function Animate.set_ylim>, 'set_zlim': <function Animate.set_zlim>, 'set_xlabel': <function Animate.set_xlabel>, 'set_ylabel': <function Animate.set_ylabel>, 'set_zlabel': <function Animate.set_zlabel>, '__dict__': <attribute '__dict__' of 'Animate' objects>, '__weakref__': <attribute '__weakref__' of 'Animate' objects>, '__annotations__': {}})
__module__ = 'spatialmath.base.animate'
__weakref__

list of weak references to the object (if defined)

class Animate2(axes=None, dims=None, labels=('X', 'Y'), **kwargs)[source]

Bases: object

Animate objects for matplotlib 2d

An instance of this class behaves like an Axes3D and supports proxies for

  • plot

  • quiver

  • text

which renders them and also places corresponding objects into a display list. These objects are Line, Quiver and Text. Only these primitives will be animated.

The objects are all drawn relative to the origin, and will be transformed according to the transform that is being animated.

Example:

anim = animate.Animate(dims=[0,2]) # set up the 3D axes
anim.trplot(T, frame='A', color='green')  # draw the frame
anim.run(loop=True)  # animate it
__init__(axes=None, dims=None, labels=('X', 'Y'), **kwargs)[source]

Construct an Animate object

Parameters
  • axes (Axes3D reference) – the axes to plot into, defaults to current axes

  • dims (array_like(4) or array_like(2)) – dimension of plot volume as [xmin, xmax, ymin, ymax]. If dims is [min, max] those limits are applied to the x- and y-axes.

  • projection (str) – 3D projection: ortho [default] or persp

  • labels (3-tuple of strings) – labels for the axes, defaults to X, Y and Z

Will setup to plot into an existing or a new Axes3D instance.

__repr__()[source]

Human readable version of the display list

Parameters

self (Animate) – the animation

Returns

readable version of the display list

Return type

str

__str__()[source]

Return str(self).

artists()[source]

List of artists that need to be updated

Parameters

self (Animate) – the animation

Returns

list of artists

Return type

list

autoscale(*args, **kwargs)[source]
plot(x, y, *args, **kwargs)[source]

Plot a polyline

Parameters
  • x (array_like) – list of x-coordinates

  • y (array_like) – list of y-coordinates

Other arguments as accepted by the matplotlib method.

All arrays must have the same length.

Seealso

matplotlib.pyplot.plot()

quiver(x, y, u, v, *args, **kwargs)[source]

Plot a quiver

Parameters
  • x (array_like) – list of base x-coordinates

  • y (array_like) – list of base y-coordinates

  • u (array_like) – list of vector x-coordinates

  • v (array_like) – list of vector y-coordinates

Draws a series of arrows, the bases defined by corresponding elements of (x,y,z) and the vector has components defined by corresponding elements of (u,v,w).

Other arguments as accepted by the matplotlib method.

Seealso

matplotlib.pyplot.quiver()

run(movie=None, axes=None, repeat=False, interval=50, nframes=100, wait=False, **kwargs)[source]

Run the animation

Parameters
  • axes (Axes reference) – the axes to plot into, defaults to current axes

  • nframes (int) – number of steps in the animation [defaault 100]

  • repeat (bool) – animate in endless loop [default False]

  • interval (int) – number of milliseconds between frames [default 50]

  • movie (str, bool) – name of file to write MP4 movie into or True

Returns

Matplotlib animation object

Return type

Matplotlib animation object

Animates a 3D coordinate frame moving from the world frame to a frame represented by the SO(2) or SE(2) matrix to the current axes.

Note

  • the movie option requires the ffmpeg package to be installed: conda install -c conda-forge ffmpeg

  • if movie=True then return an HTML5 video which can be displayed in a notebook using HTML()

  • invokes the draw() method of every object in the display list

scatter(x, y, s=0, **kwargs)[source]
set_aspect(*args, **kwargs)[source]
set_xlabel(*args, **kwargs)[source]
set_xlim(*args, **kwargs)[source]
set_ylabel(*args, **kwargs)[source]
set_ylim(*args, **kwargs)[source]
text(x, y, *args, **kwargs)[source]

Plot text

Parameters
  • x (float) – x-coordinate

  • y (float) – float

  • z (float) – z-coordinate

  • kwargs – Other arguments as accepted by the matplotlib method.

.text(x, y, s) display the string s at coordinate (x, y).

Seealso

matplotlib.pyplot.text()

trplot2(end, start=None, **kwargs)[source]

Define the transform to animate

Parameters
  • end (ndarray(3,3) or ndarray(2,2)) – the final pose SE(2) or SO(2) to display as a coordinate frame

  • start (ndarray(3,3) or ndarray(2,2)) – the initial pose SE(2) or SO(2) to display as a coordinate frame, defaults to null

Is polymorphic with base.trplot and accepts the same parameters. This sets up the animation but doesn’t execute it.

Seealso

run()

__dict__ = mappingproxy({'__module__': 'spatialmath.base.animate', '__doc__': "\n    Animate objects for matplotlib 2d\n\n    An instance of this class behaves like an Axes3D and supports proxies for\n\n    - ``plot``\n    - ``quiver``\n    - ``text``\n\n    which renders them and also places corresponding objects into a display\n    list. These objects are ``Line``, ``Quiver`` and ``Text``.  Only these\n    primitives will be animated.\n\n    The objects are all drawn relative to the origin, and will be transformed\n    according to the transform that is being animated.\n\n    Example::\n\n        anim = animate.Animate(dims=[0,2]) # set up the 3D axes\n        anim.trplot(T, frame='A', color='green')  # draw the frame\n        anim.run(loop=True)  # animate it\n    ", '__init__': <function Animate2.__init__>, 'trplot2': <function Animate2.trplot2>, 'run': <function Animate2.run>, '__repr__': <function Animate2.__repr__>, '__str__': <function Animate2.__str__>, 'artists': <function Animate2.artists>, '_draw': <function Animate2._draw>, 'set_aspect': <function Animate2.set_aspect>, 'autoscale': <function Animate2.autoscale>, '_Line': <class 'spatialmath.base.animate.Animate2._Line'>, 'plot': <function Animate2.plot>, '_Quiver': <class 'spatialmath.base.animate.Animate2._Quiver'>, 'quiver': <function Animate2.quiver>, '_Text': <class 'spatialmath.base.animate.Animate2._Text'>, 'text': <function Animate2.text>, 'scatter': <function Animate2.scatter>, 'set_xlim': <function Animate2.set_xlim>, 'set_ylim': <function Animate2.set_ylim>, 'set_xlabel': <function Animate2.set_xlabel>, 'set_ylabel': <function Animate2.set_ylabel>, '__dict__': <attribute '__dict__' of 'Animate2' objects>, '__weakref__': <attribute '__weakref__' of 'Animate2' objects>, '__annotations__': {}})
__module__ = 'spatialmath.base.animate'
__weakref__

list of weak references to the object (if defined)