Visualize

plonk.image(snap, quantity, *, x='x', y='y', interp='projection', weighted=False, slice_normal=None, slice_offset=None, extent=None, units=None, ax=None, ax_kwargs={}, colorbar_kwargs={}, **kwargs)

Visualize scalar SPH data as an image.

Visualize scalar smoothed particle hydrodynamics data by interpolation to a pixel grid.

Parameters
  • snap (SnapLike) – The Snap (or SubSnap) object to visualize.

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

  • x (str) – The x-coordinate for the visualization. Must be a string to pass to Snap. Default is ‘x’.

  • y (str) – The y-coordinate for the visualization. Must be a string to pass to Snap. Default is ‘y’.

  • interp (str) –

    The interpolation type. Default is ‘projection’.

    • ’projection’ : 2d interpolation via projection to xy-plane

    • ’slice’ : 3d interpolation via cross-section slice.

  • weighted (bool) – Whether to density weight the interpolation or not. Default is False.

  • slice_normal (Tuple[float, float, float]) – The normal vector to the plane in which to take the cross-section slice as a tuple (x, y, z). Default is (0, 0, 1).

  • slice_offset (Union[Quantity, float]) – The offset of the cross-section slice. Default is 0.0.

  • extent (Quantity) – The range in the x and y-coord as (xmin, xmax, ymin, ymax) where xmin, etc. can be floats or quantities with units of length. The default is to set the extent to a box of size such that 99% of particles are contained within.

  • units (Dict[str, str]) – The units of the plot as a dictionary. The keys correspond to quantities such as ‘position’, ‘density’, ‘velocity’, and so on. The values are strings representing units, e.g. ‘g/cm^3’ for density. There is a special key ‘projection’ that corresponds to the length unit in the direction of projection for projected interpolation plots.

  • ax (Any) – A matplotlib Axes handle.

  • ax_kwargs – Keyword arguments to pass to matplotlib Axes.

  • colorbar_kwargs – Keyword arguments to pass to matplotlib Colorbar.

  • **kwargs – Additional keyword arguments to pass to interpolation and matplotlib functions.

Returns

The matplotlib Axes object.

Return type

ax

Notes

Additional parameters passed as keyword arguments will be passed to lower level functions as required. E.g. Plonk uses matplotlib’s imshow for a image plot, so additional arguments to imshow can be passed this way.

See below for additional parameters for interpolation, colorbars, etc. All other keyword arguments are passed to the appropriate matplotlib function.

Parameters
  • num_pixels (tuple) – The number of pixels to interpolate particle quantities to as a tuple (nx, ny). Default is (512, 512).

  • show_colorbar (bool) – Whether or not to display a colorbar. Default is True.

  • snap (SnapLike) –

  • quantity (str) –

  • x (str) –

  • y (str) –

  • interp (str) –

  • weighted (bool) –

  • slice_normal (Tuple[float, float, float]) –

  • slice_offset (Union[Quantity, float]) –

  • extent (Quantity) –

  • units (Dict[str, str]) –

  • ax (Any) –

Return type

Any

Examples

Show an image of the surface density in xy-plane.

>>> plonk.image(snap=snap, quantity='density')

Alternatively, access the function as a method on the Snap object.

>>> snap.image(quantity='density')

Set units for the plot.

>>> units = {'position': 'au', 'density': 'g/cm^3', 'projection': 'cm'}
>>> snap.image(quantity='density', units=units)

Show a slice image of the density in xy-plane at z=0.

>>> snap.image(quantity='density', interp='slice')
plonk.plot(snap, *, x='x', y='y', c=None, s=None, units=None, xlim=None, ylim=None, ax=None, ax_kwargs={}, colorbar_kwargs={}, **kwargs)

Visualize SPH data as a particle plot.

Visualize SPH data by plotting the particles, or a subset of the particles, possibly with marker colors and different sizes.

Parameters
  • snap (SnapLike) – The Snap (or SubSnap) object to visualize.

  • x (str) – The x-coordinate for the visualization. Must be a string to pass to Snap. Default is ‘x’.

  • y (str) – The y-coordinate for the visualization. Must be a string to pass to Snap. Default is ‘y’.

  • c (str) – The quantity to color the particles. Must be a string to pass to Snap.

  • s (str) – The quantity to set the particle size. Must be a string to pass to Snap.

  • units (Dict[str, str]) – The units of the plot as a dictionary. The keys correspond to quantities such as ‘position’, ‘density’, ‘velocity’, and so on. The values are strings representing units, e.g. ‘g/cm^3’ for density.

  • xlim (Quantity) – The range in the x-coord as (xmin, xmax) where xmin/xmax can be floats or quantities with units of length.

  • ylim (Quantity) – The range in the y-coord as (ymin, ymax) where ymin/ymax can be floats or quantities with units of length.

  • ax (Any) – A matplotlib Axes handle.

  • ax_kwargs – Keyword arguments to pass to matplotlib Axes.

  • colorbar_kwargs – Keyword arguments to pass to matplotlib Colorbar.

  • **kwargs – Additional keyword arguments to pass to matplotlib functions.

Returns

The matplotlib Axes object.

Return type

ax

Examples

Show the particles in xy-plane.

>>> plonk.plot(snap=snap)

Alternatively, access the function as a method on the Snap object.

>>> snap.plot()

Plot density against x.

>>> snap.plot(x='x', y='density')

Color particles by density.

>>> snap.plot(x='x', y='y', c='density')

Set units for the plot.

>>> units = {'position': 'au', 'density': 'g/cm^3'}
>>> snap.plot(x='x', y='y', c='density', units=units)
plonk.vector(snap, quantity, *, x='x', y='y', interp='projection', weighted=False, slice_normal=None, slice_offset=None, extent=None, units=None, ax=None, ax_kwargs={}, **kwargs)

Visualize vector SPH data as a vector plot.

Visualize scalar smoothed particle hydrodynamics data by interpolation to a pixel grid of arrows.

Parameters
  • snap (SnapLike) – The Snap (or SubSnap) object to visualize.

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

  • x (str) – The x-coordinate for the visualization. Must be a string to pass to Snap. Default is ‘x’.

  • y (str) – The y-coordinate for the visualization. Must be a string to pass to Snap. Default is ‘y’.

  • interp (str) –

    The interpolation type. Default is ‘projection’.

    • ’projection’ : 2d interpolation via projection to xy-plane

    • ’slice’ : 3d interpolation via cross-section slice.

  • weighted (bool) – Whether to density weight the interpolation or not. Default is False.

  • slice_normal (Tuple[float, float, float]) – The normal vector to the plane in which to take the cross-section slice as a tuple (x, y, z). Default is (0, 0, 1).

  • slice_offset (Union[Quantity, float]) – The offset of the cross-section slice. Default is 0.0.

  • extent (Quantity) – The range in the x and y-coord as (xmin, xmax, ymin, ymax) where xmin, etc. can be floats or quantities with units of length. The default is to set the extent to a box of size such that 99% of particles are contained within.

  • units (Dict[str, str]) – The units of the plot as a dictionary. The keys correspond to quantities such as ‘position’, ‘density’, ‘velocity’, and so on. The values are strings representing units, e.g. ‘g/cm^3’ for density. There is a special key ‘projection’ that corresponds to the length unit in the direction of projection for projected interpolation plots.

  • ax (Any) – A matplotlib Axes handle.

  • ax_kwargs – Keyword arguments to pass to matplotlib Axes.

  • **kwargs – Additional keyword arguments to pass to interpolation and matplotlib functions.

Returns

The matplotlib Axes object.

Return type

ax

Notes

Additional parameters passed as keyword arguments will be passed to lower level functions as required.

See below for additional parameters for interpolation, vector properties, etc. All other keyword arguments are passed to the appropriate matplotlib function.

Parameters
  • num_pixels (tuple) – The number of pixels to interpolate particle quantities to as a tuple (nx, ny). Default is (512, 512).

  • number_of_arrows (tuple) – The number of arrows to display by sub-sampling the interpolated data. Default is (25, 25).

  • normalize_vectors (bool) – Whether to normalize the arrows to all have the same length. Default is False.

  • snap (SnapLike) –

  • quantity (str) –

  • x (str) –

  • y (str) –

  • interp (str) –

  • weighted (bool) –

  • slice_normal (Tuple[float, float, float]) –

  • slice_offset (Union[Quantity, float]) –

  • extent (Quantity) –

  • units (Dict[str, str]) –

  • ax (Any) –

Return type

Any

Examples

Show a vector plot of velocity in xy-plane.

>>> plonk.vector(snap=snap, quantity='velocity')

Alternatively, access the function as a method on the Snap object.

>>> snap.vector(quantity='velocity')

Set units for the plot.

>>> units = {'position': 'au', 'velocity': 'km/s', 'projection': 'km'}
>>> snap.vector(quantity='velocity', units=units)

Show a slice plot of the velocity in xy-plane at z=0.

>>> snap.vector(quantity='density', interp='slice')
plonk.visualize_sim(sim, kind, **kwargs)

Visualize a simulation.

Parameters
  • sim (Simulation) – The Simulation object.

  • kind (str) – The kind of plot: ‘particle’, ‘image’, ‘vector’.

  • **kwargs – Keyword arguments to pass to plotting methods such as plonk.image, plonk.plot, and plonk.vector.

Returns

Return type

VisualizeSimulation

Examples

Visualize a simulation by density projection images.

>>> viz = visualize_sim(sim=sim, kind='image', quantity='density')

Alternatively.

>>> sim.visualize(kind='image', quantity='density')

Go forwards and backwards through snaps.

>>> viz.next()
>>> viz.prev()

Go to a particular snap, or skip ahead.

>>> viz.goto(10)
>>> viz.next(5)