sfs.plot2d

2D plots of sound fields etc.

Functions

add_colorbar(im, *[, aspect, pad])

Add a vertical color bar to a plot.

amplitude(p, grid, *[, xnorm, cmap, vmin, …])

Two-dimensional plot of sound field (real part).

level(p, grid, *[, xnorm, power, cmap, …])

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

loudspeakers(x0, n0[, a0, size, …])

Draw loudspeaker symbols at given locations and angles.

particles(x, *[, trim, ax, xlabel, ylabel, …])

Plot particle positions as scatter plot.

reference(xref, *[, size, ax])

Draw reference/normalization point.

secondary_sources(x0, n0, *[, size, grid])

Simple visualization of secondary source locations.

vectors(v, grid, *[, cmap, headlength, …])

Plot a vector field in the xy plane.

virtualsource(xs[, ns, type, ax])

Draw position/orientation of virtual source.

sfs.plot2d.virtualsource(xs, ns=None, type='point', *, ax=None)[source]

Draw position/orientation of virtual source.

sfs.plot2d.reference(xref, *, size=0.1, ax=None)[source]

Draw reference/normalization point.

sfs.plot2d.secondary_sources(x0, n0, *, size=0.05, grid=None)[source]

Simple visualization of secondary source locations.

Parameters
  • x0 ((N, 3) array_like) – Loudspeaker positions.

  • n0 ((N, 3) or (3,) array_like) – Normal vector(s) of loudspeakers.

  • size (float, optional) – Size of loudspeakers in metres.

  • grid (triple of array_like, optional) – If specified, only loudspeakers within the grid are shown.

sfs.plot2d.loudspeakers(x0, n0, a0=0.5, *, size=0.08, show_numbers=False, grid=None, ax=None)[source]

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.plot2d.amplitude(p, grid, *, xnorm=None, cmap='coolwarm_clip', vmin=- 2.0, vmax=2.0, xlabel=None, ylabel=None, colorbar=True, colorbar_kwargs={}, ax=None, **kwargs)[source]

Two-dimensional plot of sound field (real part).

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.plot2d.level

sfs.plot2d.level(p, grid, *, xnorm=None, power=False, cmap=None, vmax=3, vmin=- 50, **kwargs)[source]

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

Takes the same parameters as sfs.plot2d.amplitude().

Other Parameters

power (bool, optional) – See sfs.util.db().

sfs.plot2d.particles(x, *, trim=None, ax=None, xlabel='x (m)', ylabel='y (m)', edgecolors=None, marker='.', s=15, **kwargs)[source]

Plot particle positions as scatter plot.

Parameters

x (triple or pair of array_like) – x, y and optionally z components of particle positions. The z components are ignored. If the values are complex, the imaginary parts are ignored.

Returns

Scatter – See matplotlib.pyplot.scatter().

Other Parameters
  • trim (array of float, optional) – xmin, xmax, ymin, ymax limits for which the particles are plotted.

  • ax (Axes, optional) – If given, the plot is created on ax instead of the current axis (see matplotlib.pyplot.gca()).

  • xlabel, ylabel (str) – Overwrite default x/y labels. Use xlabel='' and ylabel='' to remove x/y labels. The labels can be changed afterwards with matplotlib.pyplot.xlabel() and matplotlib.pyplot.ylabel().

  • edgecolors, markr, s, **kwargs – All further parameters are forwarded to matplotlib.pyplot.scatter().

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

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.plot2d.add_colorbar(im, *, aspect=20, pad=0.5, **kwargs)[source]

Add a vertical color bar to a plot.

Parameters