Animation

plonk.animate(filename, *, snaps=None, profiles=None, quantity=None, x=None, y=None, fig=None, adaptive_colorbar=True, adaptive_limits=True, text=None, text_kwargs={}, func_animation_kwargs={}, save_kwargs={}, **kwargs)

Animate a Snap or Profile visualization.

Pass in a list of Snap objects or Profile objects. If snaps are passed in and the quantity is None, then the animation will be of particle plots, otherwise it will be of images. If profiles are passed in the animation will be of profiles.

Parameters
  • filename (Union[str, Path]) – The file name to save the animation to.

  • snaps (List[SnapLike]) – A list of Snap objects to animate.

  • profiles (List[Profile]) – A list of Profile objects to animate.

  • quantity (optional) – The quantity to visualize. Must be a string to pass to Snap.

  • x (optional) – The quantity for the x-axis. Must be a string to pass to Snap. For interpolated plots must be ‘x’, ‘y’, or ‘z’.

  • y (optional) – The quantity for the y-axis. Must be a string to pass to Snap. For interpolated plots must be ‘x’, ‘y’, or ‘z’.

  • fig (optional) – A matplotlib Figure object to animate. If None, generate a new Figure.

  • adaptive_colorbar (optional) – If True, adapt colorbar range during animation. If False, the colorbar range is fixed by the initial image. Default is True.

  • adaptive_limits (optional) – If True, adapt plot limits during animation. If False, the plot limits are fixed by the initial plot. Default is True.

  • text (optional) – List of strings to display per snap.

  • text_kwargs (optional) – Keyword arguments to pass to matplotlib text.

  • func_animation_kwargs (optional) – Keyword arguments to pass to matplotlib FuncAnimation.

  • save_kwargs (optional) – Keyword arguments to pass to matplotlib Animation.save.

  • **kwargs – Arguments to pass to visualize.image.

Returns

The matplotlib FuncAnimation object.

Return type

anim

Examples

Make an image animation of projected density.

>>> units = {
...     'position': 'au',
...     'density': 'g/cm^3',
...     'projection': 'cm'
... }
>>> plonk.animate(
...     filename='animation.mp4',
...     snaps=snaps,
...     quantity='density',
...     units=units,
...     save_kwargs={'fps': 10, 'dpi': 300},
... )

Make a particle animation of x vs density.

>>> units = {'position': 'au', 'density': 'g/cm^3'}
>>> plonk.animate(
...     filename='animation.mp4',
...     snaps=snaps,
...     x='x',
...     y='density',
...     units=units,
...     adaptive_limits=False,
...     save_kwargs={'fps': 10, 'dpi': 300},
... )

Make a profile animation of radius vs surface density.

>>> units={'position': 'au', 'surface_density': 'g/cm^2'}
>>> plonk.animate(
...     filename='animation.mp4',
...     profiles=profiles,
...     x='radius',
...     y='surface_density',
...     units=units,
...     adaptive_limits=False,
...     save_kwargs={'fps': 10, 'dpi': 300},
... )
plonk.visualize.animation_images(*, filename, snaps, quantity, fig=None, adaptive_colorbar=True, text=None, text_kwargs={}, func_animation_kwargs={}, save_kwargs={}, **kwargs)

Generate an animation of images.

Parameters
  • filename (Union[str, Path]) – The file name to save the animation to.

  • snaps (List[SnapLike]) – A list of Snap objects to animate.

  • quantity (str) – The quantity to visualize. Must be a string to pass to Snap.

  • fig (optional) – A matplotlib Figure object to animate. If None, generate a new Figure.

  • adaptive_colorbar (optional) – If True, adapt colorbar range during animation. If False, the colorbar range is fixed by the initial image. Default is True.

  • text (optional) – List of strings to display per snap.

  • text_kwargs (optional) – Keyword arguments to pass to matplotlib text.

  • func_animation_kwargs (optional) – Keyword arguments to pass to matplotlib FuncAnimation.

  • save_kwargs (optional) – Keyword arguments to pass to matplotlib Animation.save.

  • **kwargs – Arguments to pass to visualize.image.

Returns

The matplotlib FuncAnimation object.

Return type

anim

Examples

Make an animation of projected density.

>>> animation_images(
...     filename='animation.mp4',
...     snaps=snaps,
...     quantity='density',
...     units={'position': 'au', 'density': 'g/cm^3'},
...     save_kwargs={'fps': 10, 'dpi': 300},
... )
plonk.visualize.animation_particles(*, filename, snaps, fig=None, adaptive_limits=True, text=None, text_kwargs={}, func_animation_kwargs={}, save_kwargs={}, **kwargs)

Generate an animation of particle plots.

Parameters
  • filename (Union[str, Path]) – The file name to save the animation to.

  • snaps (List[SnapLike]) – A list of Snap objects to animate.

  • fig (optional) – A matplotlib Figure object to animate. If None, generate a new Figure.

  • adaptive_limits (optional) – If True, adapt plot limits during animation. If False, the plot limits are fixed by the initial plot. Default is True.

  • text (optional) – List of strings to display per snap.

  • text_kwargs (optional) – Keyword arguments to pass to matplotlib text.

  • func_animation_kwargs (optional) – Keyword arguments to pass to matplotlib FuncAnimation.

  • save_kwargs (optional) – Keyword arguments to pass to matplotlib Animation.save.

  • **kwargs – Arguments to pass to visualize.plot.

Returns

The matplotlib FuncAnimation object.

Return type

anim

Examples

Make an animation of x vs density on the particles.

>>> animation_particles(
...     filename='animation.mp4',
...     snaps=snaps,
...     x='x',
...     y='density',
...     adaptive_limits=False,
...     save_kwargs={'fps': 10, 'dpi': 300},
... )
plonk.visualize.animation_profiles(*, filename, profiles, x, y, fig=None, adaptive_limits=True, text=None, text_kwargs={}, func_animation_kwargs={}, save_kwargs={}, **kwargs)

Generate an animation of a profile.

Parameters
  • filename (Union[str, Path]) – The file name to save the animation to.

  • profiles (List[Profile]) – A list of Profile objects to animate.

  • x (str) – The quantity for the x-axis. Must be a string to pass to Snap.

  • y (Union[str, List[str]]) – The quantity for the y-axis, or list of quantities. Must be a string (or list of strings) to pass to Snap.

  • fig (optional) – A matplotlib Figure object to animate. If None, generate a new Figure.

  • adaptive_limits (optional) – If True, adapt plot limits during animation. If False, the plot limits are fixed by the initial plot. Default is True.

  • text (optional) – List of strings to display per profile plot.

  • text_kwargs (optional) – Keyword arguments to pass to matplotlib text.

  • func_animation_kwargs (optional) – Keyword arguments to pass to matplotlib FuncAnimation.

  • save_kwargs (optional) – Keyword arguments to pass to matplotlib Animation.save.

  • **kwargs – Arguments to pass to Profile.plot function.

Returns

The matplotlib FuncAnimation object.

Return type

anim

Examples

Make an animation of radius vs surface density.

>>> animation_profiles(
...     filename='animation.mp4',
...     profiles=profiles,
...     x='radius',
...     y='surface_density',
...     units={'position': 'au', 'surface_density': 'g/cm^2'},
...     adaptive_limits=False,
...     save_kwargs={'fps': 10, 'dpi': 300},
... )