Plotting

Plot sound fields etc.

sfs.plot.add_colorbar(im, aspect=20, pad=0.5, **kwargs)

Add a vertical color bar to a plot.

Parameters:
sfs.plot.level(p, grid, xnorm=None, power=False, cmap=None, vmax=3, vmin=-50, **kwargs)

Two-dimensional plot of level (dB) of sound field.

Takes the same parameters as sfs.plot.soundfield().

Other Parameters:
 power (bool, optional) – See sfs.util.db().
sfs.plot.loudspeaker_2d(x0, n0, a0=0.5, size=0.08, show_numbers=False, grid=None, ax=None)

Draw loudspeaker symbols at given locations and angles.

Parameters:
  • x0 ((N, 3) array_like) – Loudspeaker positions.
  • n0 ((N, 3) or (3,) array_like) – Normal vector(s) of loudspeakers.
  • a0 (float or (N,) array_like, optional) – Weighting factor(s) of loudspeakers.
  • size (float, optional) – Size of loudspeakers in metres.
  • show_numbers (bool, optional) – If True, loudspeaker numbers are shown.
  • grid (triple of array_like, optional) – If specified, only loudspeakers within the grid are shown.
  • ax (Axes object, optional) – The loudspeakers are plotted into this matplotlib.axes.Axes object or – if not specified – into the current axes.
sfs.plot.loudspeaker_3d(x0, n0, a0=None, w=0.08, h=0.08)

Plot positions and normals of a 3D secondary source distribution.

sfs.plot.particles(x, trim=None, ax=None, xlabel='x (m)', ylabel='y (m)', edgecolor='', **kwargs)

Plot particle positions as scatter plot

sfs.plot.reference_2d(xref, size=0.1, ax=None)

Draw reference/normalization point.

sfs.plot.secondarysource_2d(x0, n0, grid=None)

Simple plot of secondary source locations.

sfs.plot.soundfield(p, grid, xnorm=None, cmap='coolwarm_clip', vmin=-2.0, vmax=2.0, xlabel=None, ylabel=None, colorbar=True, colorbar_kwargs={}, ax=None, **kwargs)

Two-dimensional plot of sound field.

Parameters:
  • p (array_like) – Sound pressure values (or any other scalar quantity if you like). If the values are complex, the imaginary part is ignored. Typically, p is two-dimensional with a shape of (Ny, Nx), (Nz, Nx) or (Nz, Ny). This is the case if sfs.util.xyz_grid() was used with a single number for z, y or x, respectively. However, p can also be three-dimensional with a shape of (Ny, Nx, 1), (1, Nx, Nz) or (Ny, 1, Nz). This is the case if numpy.meshgrid() was used with a scalar for z, y or x, respectively (and of course with the default indexing='xy').

    Note

    If you want to plot a single slice of a pre-computed “full” 3D sound field, make sure that the slice still has three dimensions (including one singleton dimension). This way, you can use the original grid of the full volume without changes. This works because the grid component corresponding to the singleton dimension is simply ignored.

  • grid (triple or pair of numpy.ndarray) – The grid that was used to calculate p, see sfs.util.xyz_grid(). If p is two-dimensional, but grid has 3 components, one of them must be scalar.

  • xnorm (array_like, optional) – Coordinates of a point to which the sound field should be normalized before plotting. If not specified, no normalization is used. See sfs.util.normalize().

Returns:

AxesImage – See matplotlib.pyplot.imshow().

Other Parameters:
 

See also

sfs.plot.level()

sfs.plot.vectors(v, grid, cmap='blacktransparent', headlength=3, headaxislength=2.5, ax=None, clim=None, **kwargs)

Plot a vector field in the xy plane.

Parameters:
  • v (triple or pair of array_like) – x, y and optionally z components of vector field. The z components are ignored. If the values are complex, the imaginary parts are ignored.
  • grid (triple or pair of array_like) – The grid that was used to calculate v, see sfs.util.xyz_grid(). Any z components are ignored.
Returns:

Quiver – See matplotlib.pyplot.quiver().

Other Parameters:
 
sfs.plot.virtualsource_2d(xs, ns=None, type='point', ax=None)

Draw position/orientation of virtual source.