sfs.plot2d¶
2D plots of sound fields etc.
Functions
|
Add a vertical color bar to a plot. |
|
Two-dimensional plot of sound field (real part). |
|
Two-dimensional plot of level (dB) of sound field. |
|
Draw loudspeaker symbols at given locations and angles. |
|
Plot particle positions as scatter plot. |
|
Draw reference/normalization point. |
|
Simple visualization of secondary source locations. |
|
Plot a vector field in the xy plane. |
|
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.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 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.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=''
andylabel=''
to remove x/y labels. The labels can be changed afterwards withmatplotlib.pyplot.xlabel()
andmatplotlib.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
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 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