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, *[, grid]) Simple plot 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, *, grid=None)[source]

Simple plot of secondary source locations.

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: Returns: 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(). AxesImage – See matplotlib.pyplot.imshow(). 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(). colorbar (bool, optional) – If False, no colorbar is created. colorbar_kwargs (dict, optional) – Further colorbar arguments, see add_colorbar(). ax (Axes, optional) – If given, the plot is created on ax instead of the current axis (see matplotlib.pyplot.gca()). cmap, vmin, vmax, **kwargs – All further parameters are forwarded to matplotlib.pyplot.imshow().
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)', edgecolor='', marker='.', s=15, **kwargs)[source]

Plot particle positions as scatter plot

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: Returns: 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. Quiver – See matplotlib.pyplot.quiver(). ax (Axes, optional) – If given, the plot is created on ax instead of the current axis (see matplotlib.pyplot.gca()). clim (pair of float, optional) – Limits for the scaling of arrow colors. See matplotlib.pyplot.quiver(). cmap, headlength, headaxislength, **kwargs – All further parameters are forwarded to matplotlib.pyplot.quiver().
sfs.plot2d.add_colorbar(im, *, aspect=20, pad=0.5, **kwargs)[source]

Add a vertical color bar to a plot.

Parameters: im (ScalarMappable) – The output of sfs.plot2d.amplitude(), sfs.plot2d.level() or any other matplotlib.cm.ScalarMappable. aspect (float, optional) – Aspect ratio of the colorbar. Strictly speaking, since the colorbar is vertical, it’s actually the inverse of the aspect ratio. pad (float, optional) – Space between image plot and colorbar, as a fraction of the width of the colorbar. Note The pad argument of matplotlib.figure.Figure.colorbar() has a slightly different meaning (“fraction of original axes”)! **kwargs – All further arguments are forwarded to matplotlib.figure.Figure.colorbar().