Plotting Module¶
Matplotlib plotting for datasets.
PlotData is the object returned by DataSet.plot_time_data,
plot_freq_data, plot_tf_data and plot_sono_data. It wraps a
matplotlib figure (fig, ax, and ax2 for coherence), so anything
matplotlib can do to a figure you can do to it.
A PlotData can also stand in for a time range. Pass it as
time_range= to calculate_fft or calculate_cross_spectrum_matrix,
and the range is read from the current x-axis limits of the plot: zoom
the plot, then analyse what you see. Elsewhere, pass the range as a list
such as [0.5, 1.5]: a transfer function computed with a PlotData
range can't be saved afterwards.
For custom figures, use matplotlib directly, as shown in the Plotting Guide.
PlotData ¶
A matplotlib figure showing one list of data from a DataSet.
DataSet.plot_time_data, plot_freq_data, plot_tf_data and
plot_sono_data each create one and return it. Use its fig and
ax with matplotlib as usual, or call update to redraw it with
other data or another view.
Lines are either highlighted or faint. Clicking a line in the legend
toggles it, and get_selected_channels reports the current state.
auto_x and auto_y scale the axes to the highlighted lines only.
A PlotData can stand in for a time range: pass it as time_range
to analysis.calculate_fft or analysis.calculate_cross_spectrum_matrix
(or DataSet.calculate_fft_set) and the range is read from the
current x-axis limits (ax.get_xbound()), so you can zoom the
plot and then analyse what is shown.
On a desktop (interactive, non-notebook) matplotlib backend the figure window is shown on creation.
Parameters:
-
window_title(str, default:None) –Accepted and ignored.
-
sets(str or list[int], default:'all') –Accepted and ignored; pass it to
update. -
channels(str or list[int], default:'all') –Accepted and ignored; pass it to
update. -
figsize(tuple, default:(9, 5)) –Figure size in inches (default
(9, 5)). -
canvas(object, default:None) –An existing matplotlib canvas to draw on instead of creating a new figure.
-
fig(Figure, default:None) –The figure belonging to
canvas.
Attributes:
-
fig(Figure) –The figure.
-
ax(Axes) –The main axes.
-
ax2(Axes) –A twin y-axis for coherence, shown only for transfer functions.
-
legend(Legend) –The legend of
ax, once data has been drawn. -
line_listbyset(list) –For each set, the list of its
matplotliblines onax, one per channel. -
data_list(list) –The data list last drawn.
-
pcolor_sono(object) –The colour mesh of the last sonogram drawn, or None.
Attributes¶
Methods:¶
update ¶
update(data_list, sets='all', channels='all', xlinlog='linear', show_coherence=True, plot_type=None, coherence_plot_type='linear', freq_range=None, auto_xy='xyc')
Redraw the figure with a list of time, frequency or TF data.
Each channel is multiplied by its item's channel_cal_factors.
Lines outside sets / channels are drawn faint. For a
TfDataList, NaN values in tf_coherence are replaced by 1 in
place.
Parameters:
-
data_list(TimeDataList or FreqDataList or TfDataList) –The data to draw.
-
sets(str or list[int], default:'all') –'all'(the default) or the set indices to highlight. -
channels(str or list[int], default:'all') –'all'(the default) or the channel indices to highlight in every set. -
xlinlog(str, default:'linear') –'linear'(the default) or'log'frequency axis, for frequency and TF data. -
show_coherence(bool, default:True) –Draw TF coherence dotted on
ax2(default True). It is not drawn when every set's coherence is missing or identically 1. -
plot_type(str, default:None) –For frequency and TF data:
'Amplitude (dB)'(the default, also used for None),'Amplitude (linear)','Real Part','Imag Part','Phase'(degrees) or'Nyquist'(imaginary against real part). -
coherence_plot_type(str, default:'linear') –'linear'(the default) or'log'(in dB). -
freq_range(list, default:None) –[f_min, f_max]in Hz. For a Nyquist plot only points strictly inside it are drawn; with'f'inauto_xyit sets the x-axis limits. -
auto_xy(str, default:'xyc') –Which axes to rescale after drawing, as letters:
'x'and'y'fit the highlighted lines,'c'resets the coherence axis to 0..1, and'f'sets the x-axis tofreq_range(which must then be given). Default'xyc'.
update_legend ¶
Rebuild the legend and make its entries clickable.
Called by update. Legend entries mirror the opacity of their
lines; 10 or more lines are laid out in several columns.
Parameters:
-
loc(str, default:'lower right') –Legend location, as for matplotlib (default
'lower right'). -
draggable(bool, default:False) –Let the legend be dragged with the mouse (default False).
auto_x ¶
Fit the x-axis to the highlighted lines (or a sonogram's time axis).
On a log frequency axis the fit starts at the first non-zero frequency. A Nyquist plot keeps equal axis scaling.
auto_y ¶
Fit the y-axis to the highlighted lines within the current x-range.
For a sonogram the y-axis is set to its frequency axis. For transfer functions the coherence axis is reset to 0..1.
channel_select ¶
Toggle a line between highlighted and faint when its legend entry is clicked.
Connected to the figure's pick events automatically; the matching coherence line follows.
Parameters:
-
event(PickEvent) –The pick event.
get_selected_channels ¶
Report which lines are currently highlighted.
Returns:
-
selected(list[list[bool]]) –For each set, one flag per channel, True where the line is highlighted.
set_selected_channels ¶
Highlight lines from a list of flags, as returned by get_selected_channels.
Parameters:
-
s(list[list[bool]]) –For each set, one flag per channel; True highlights the line and False makes it faint. Its shape must match the lines drawn.
update_sonogram ¶
Redraw the figure as a colour map of one sonogram channel.
The magnitude is shown in dB, using the 'Blues' colour map.
Exact zeros in that channel's sono_data are replaced by 1e-16 in
place, to avoid taking the log of zero.
Parameters:
-
sono_data_list(SonoDataList) –The sonograms.
-
n_set(int) –Index of the sonogram in the list.
-
n_chan(int) –Channel (plane) index within it.
-
db_range(float, default:60) –Colour-scale range in dB below the maximum (default 60).
-
auto_xy(str, default:'xy') –'x'and/or'y'to fit that axis to the sonogram (default'xy').
PlotSonoData ¶
A bare matplotlib figure for one sonogram channel.
Not used by pydvma itself: DataSet.plot_sono_data draws sonograms
with PlotData.update_sonogram, which adds a dB colour range and
axis scaling. Kept for code that creates one directly.
Parameters:
-
figsize(tuple, default:(9, 5)) –Figure size in inches (default
(9, 5)). -
canvas(object, default:None) –An existing matplotlib canvas to draw on instead of creating a new figure.
-
fig(Figure, default:None) –The figure belonging to
canvas.
Attributes:
Attributes¶
Methods:¶
update ¶
Draw one channel of one sonogram, magnitude in dB.
Parameters:
-
sono_data_list(SonoDataList) –The sonograms.
-
n_set(int, default:0) –Index of the sonogram in the list (default 0).
-
n_chan(int, default:0) –Channel (plane) index within it (default 0).