Skip to content

spectrogram_plot

MATLAB equivalent: sidSpectrogramPlot

spectrogram_plot

Spectrogram colour map plot.

spectrogram_plot

spectrogram_plot(result: SpectrogramResult, *, frequency_scale: str = 'linear', channel: int = 0, clim: tuple | None = None, ax=None) -> dict

Spectrogram colour map plot.

This is the Python port of sidSpectrogramPlot.m.

Plots the spectrogram as a time-frequency colour map with power in dB.

Parameters:

Name Type Description Default
result SpectrogramResult

Result struct returned by :func:sid.spectrogram.

required
frequency_scale str

'linear' (default) or 'log'.

'linear'
channel int

Zero-based channel index for multi-channel data. Default is 0.

0
clim tuple of (float, float) or None

Colour axis limits (cmin, cmax) in dB. None for automatic scaling (default).

None
ax matplotlib Axes or None

Existing axes to plot into. If None, a new figure is created.

None

Returns:

Type Description
dict

Dictionary with the following keys:

  • 'fig' -- matplotlib Figure handle.
  • 'ax' -- Axes handle.
  • 'mesh' -- QuadMesh handle from pcolormesh.

Raises:

Type Description
SidError

If result is not a SpectrogramResult (code: 'invalid_result').

SidError

If channel is out of range (code: 'invalid_channel').

Examples:

>>> import numpy as np
>>> import sid
>>> Fs = 1000; Ts = 1 / Fs; N = 5000
>>> t = np.arange(N) * Ts
>>> x = np.cos(2 * np.pi * (50 + 100 * t / t[-1]) * t)
>>> result = sid.spectrogram(x, window_length=256, sample_time=Ts)
>>> h = sid.spectrogram_plot(result)
Notes

Specification: SPEC.md S7.5 -- Visualization

The channel parameter is 0-indexed (Python convention), unlike MATLAB's 1-indexed Channel option.

See Also

sid.spectrogram : Compute a spectrogram. sid.map_plot : Time-frequency map for freq_map results.

Changelog

2026-04-09 : First version (Python port) by Pedro Lourenco.