Last updated on Aug 22, 2025.

netsse.tools.viz.plot_dirwavespec#

netsse.tools.viz.plot_dirwavespec(spec, dirs, freqs, unit_dirs='deg', unit_freqs='Hz', levels=None, cmap='turbo', vmin=None, vmax=None, freq_max=None, show_dirlabels=True, show_freqlabels=True, ax=None)#

Plots the input directional wave spectrum in a polar diagram.

The plot shows the power spectral density (PSD) distribution over wave frequencies and directions.

Parameters:
  • spec (array_like) – Directional wave spectrum to be plotted. This must be a 2-D array of shape either (Ndirs,Nfreqs) or (Nfreqs,Ndirs).

  • dirs (array_like of shape (Ndirs,)) – Directions of the spectrum.

  • freqs (array_like of shape (Nfreqs,)) – Frequencies of the spectrum.

  • unit_dirs ({'deg','rad'}, optional) – Unit of the directions, either 'deg' for degrees or 'rad' for radians. Default is 'deg'.

  • unit_freqs ({'Hz','rad/s'}, optional) – Unit of the frequencies, either 'Hz' for Hertz or 'rad/s' for radians per second. Default is 'Hz'.

  • levels (array_like, optional) –

    Contour levels to use for the plot. If None, levels are automatically determined according to the formula below:

    \(vmin*(vmax/vmin)^{i/29}\) for \(i=0,1,...,29\). Default is None.

  • cmap (str, optional) –

    Colormap to use for the plot. Default is 'turbo'.

    Note

    Other colormap options include 'viridis', 'plasma', 'inferno', 'magma'. Visit the Matplotlib documentation for an overview of the options.

  • vmin (float, optional) – Minimum value for the colormap. Default is None, which means to use the value \(10^{-1/2}\).

  • vmax (float, optional) –

    Maximum value for the colormap. Default is None, which means to use the maximum value in spec.

    Warning

    vmin and vmax are used to set the colormap limits. These options will override the lower and upper limits of levels, if the latter option is used.

  • freq_max (float, optional) – Maximum frequency to plot. Default is None, which means to use the maximum frequency in the input data.

  • show_dirlabels ({True,False,'compass'}, optional) – Whether to show direction labels. If True, shows labels in degrees. If 'compass', shows compass directions. If False, no labels are shown. Default is True.

  • show_freqlabels ({True,False,'all'}, optional) – Whether to show frequency labels. If True, shows only the maximum frequency label. If 'all', shows all labels. If False, no labels are shown. Default is True.

  • ax (matplotlib.axes, optional) – Axes object to plot on. If None, a new figure and axes are created. Default is None.

Returns:

ax – The axes object with the plot.

Return type:

matplotlib.axes._subplots.PolarAxesSubplot

Example

>>> # Generate some example data
>>> freqs = np.linspace(0.05, 0.5, 50)
>>> dirs = np.linspace(0, 360, 36)
>>> spec = np.random.rand(36, 50)
>>> # Plot the directional wave spectrum
>>> plot_dirwavespec(spec, dirs, freqs)