BodePlot#

class gwpy.plot.BodePlot(
*filters: FilterType,
dB: bool = True,
frequencies: Array1D | int | None = None,
**kwargs,
)[source]#

Bases: Plot

A Plot class for visualising transfer functions.

Parameters:
filterslti, FrequencySeries

Any number of the following:

  • linear time-invariant filters, either lti or tuple of the following length and form: - 2: (numerator, denominator) - 3: (zeros, poles, gain) - 4: (A, B, C, D)

  • complex-valued spectra representing a transfer function

frequenciesnumpy.ndarray, int, optional

List of frequencies (in Hertz) at which to plot, or an integer specifying the number of frequencies to generate.

dBbool, optional

If True, display magnitude in decibels, otherwise display amplitude.

analogbool, optional

If True, indicates that the input filters are analogue filters.

sample_ratefloat, Quantity, optional

The sampling rate of a digital filter. If analog=False this option is required.

unitstr, optional

For analogue ZPK filters, the units in which the zeros and poles are specified. Either 'Hz' or 'rad/s' (default).

normalize_gainbool, optional

Whether to normalize the gain when converting from Hz to rad/s.

  • False (default): Multiply zeros/poles by -2π but leave gain unchanged. This matches the LIGO GDS ‘f’ plane convention (plane='f' in s2z()).

  • True: Normalize gain to preserve frequency response magnitude. Gain is scaled by \(|∏p_i/∏z_i| · (2π)^{(n_p - n_z)}\). Use this when your filter was designed with the transfer function \(H(f) = k·∏(f-z_i)/∏(f-p_i)\) in Hz. This matches the LIGO GDS ‘n’ plane convention (plane='n' in s2z()).

Only used for analogue filters in Hz (analog=True, unit="Hz").

kwargs

All other keyword arguments are passed to plot().

Returns:
plotBodePlot

A new BodePlot with two Axes - maxes and paxes - representing the magnitude and phase of the input transfer function(s) respectively.

Attributes Summary

maxes

FrequencySeriesAxes for the Bode magnitude.

paxes

FrequencySeriesAxes for the Bode phase.

Methods Summary

add_filter(filter_[, frequencies, dB, ...])

Add a linear time-invariant filter to this BodePlot.

add_frequencyseries(spectrum, *[, dB, power])

Plot the magnitude and phase of a complex-valued FrequencySeries.

set(*[, agg_filter, alpha, animated, ...])

Set multiple properties at once.

Attributes Documentation

maxes[source]#

FrequencySeriesAxes for the Bode magnitude.

paxes[source]#

FrequencySeriesAxes for the Bode phase.

Methods Documentation

add_filter(
filter_: FilterType,
frequencies: Array1D | int | None = None,
*,
dB: bool = True,
analog: bool = False,
sample_rate: QuantityLike = 1.0,
unit: str | None = None,
normalize_gain: bool = False,
**kwargs,
) tuple[Line2D, Line2D][source]#

Add a linear time-invariant filter to this BodePlot.

Parameters:
filter_lti, tuple

The filter to plot, either as a lti, or a tuple with the following number and meaning of elements

  • 2: (numerator, denominator)

  • 3: (zeros, poles, gain)

  • 4: (A, B, C, D)

frequenciesnumpy.ndarray, optional

List of frequencies (in Hertz) at which to plot.

dBbool, optional

If True, display magnitude in decibels, otherwise display amplitude, default: True.

analogbool, optional

If True, indicates that filter_ is an analogue filter.

sample_ratefloat, Quantity, optional

The sampling rate of a digital filter. If analog=False this option is required.

unitstr, optional

For analogue ZPK filters, the units in which the zeros and poles are specified. Either 'Hz' or 'rad/s' (default).

normalize_gainbool, optional

Whether to normalize the gain when converting from Hz to rad/s.

  • False (default): Multiply zeros/poles by -2π but leave gain unchanged. This matches the LIGO GDS ‘f’ plane convention (plane='f' in s2z()).

  • True: Normalize gain to preserve frequency response magnitude. Gain is scaled by \(|∏p_i/∏z_i| · (2π)^{(n_p - n_z)}\). Use this when your filter was designed with the transfer function \(H(f) = k·∏(f-z_i)/∏(f-p_i)\) in Hz. This matches the LIGO GDS ‘n’ plane convention (plane='n' in s2z()).

Only used for analogue filters in Hz (analog=True, unit="Hz").

kwargs

All other keyword arguments are passed to plot().

Returns:
mag, phasematplotlib.lines.Line2D

The lines drawn for the magnitude and phase of the filter.

Raises:
ValueError

If analog=False is given and sample_rate isn’t.

add_frequencyseries(
spectrum: FrequencySeries,
*,
dB: bool = True,
power: bool = False,
**kwargs,
) tuple[Line2D, Line2D][source]#

Plot the magnitude and phase of a complex-valued FrequencySeries.

Parameters:
spectrumFrequencySeries

the (complex-valued) FrequencySeries to display

dBbool, optional

If True, display magnitude in decibels, otherwise display amplitude.

powerbool, optional

Give True to incidate that spectrum holds power values, so dB = 10 * log(abs(spectrum)), otherwise db = 20 * log(abs(spectrum)). This argument is ignored if db=False.

**kwargs

All other keyword arguments are passed to plot().

Returns:
mag, phasematplotlib.lines.Line2D

The lines drawn for the magnitude and phase of the filter.

set(
*,
agg_filter=<UNSET>,
alpha=<UNSET>,
animated=<UNSET>,
canvas=<UNSET>,
clip_box=<UNSET>,
clip_on=<UNSET>,
clip_path=<UNSET>,
constrained_layout=<UNSET>,
constrained_layout_pads=<UNSET>,
dpi=<UNSET>,
edgecolor=<UNSET>,
facecolor=<UNSET>,
figheight=<UNSET>,
figwidth=<UNSET>,
frameon=<UNSET>,
gid=<UNSET>,
in_layout=<UNSET>,
label=<UNSET>,
layout_engine=<UNSET>,
linewidth=<UNSET>,
mouseover=<UNSET>,
path_effects=<UNSET>,
picker=<UNSET>,
rasterized=<UNSET>,
size_inches=<UNSET>,
sketch_params=<UNSET>,
snap=<UNSET>,
tight_layout=<UNSET>,
transform=<UNSET>,
url=<UNSET>,
visible=<UNSET>,
zorder=<UNSET>,
)#

Set multiple properties at once.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: float or None animated: bool canvas: FigureCanvas clip_box: BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: Transform url: str visible: bool zorder: float