Plotting¶
Plot sound fields etc.
-
sfs.plot.
virtualsource_2d
(xs, ns=None, type='point', ax=None)[source]¶ Draw position/orientation of virtual source.
-
sfs.plot.
loudspeaker_2d
(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.plot.
loudspeaker_3d
(x0, n0, a0=None, w=0.08, h=0.08)[source]¶ Plot positions and normals of a 3D secondary source distribution.
-
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)[source]¶ 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 ifnumpy.meshgrid()
was used with a scalar for z, y or x, respectively (and of course with the defaultindexing='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: - xlabel, ylabel (str) – Overwrite default x/y labels. Use
xlabel=''
andylabel=''
to remove x/y labels. The labels can be changed afterwards withmatplotlib.pyplot.xlabel()
andmatplotlib.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()
.
See also
-
sfs.plot.
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.plot.soundfield()
.Other Parameters: power (bool, optional) – See sfs.util.db()
.
-
sfs.plot.
particles
(x, trim=None, ax=None, xlabel='x (m)', ylabel='y (m)', edgecolor='', **kwargs)[source]¶ Plot particle positions as scatter plot
-
sfs.plot.
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: - 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.plot.
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.plot.soundfield()
,sfs.plot.level()
or any othermatplotlib.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()
.
See also