# HG changeset patch # User Amine Sehili # Date 1566845716 -7200 # Node ID a9dc1a5115a718793f4551327a024cd769496280 # Parent c422eeff8013e30da1bad10e1ded334196091293 Add plotting.py diff -r c422eeff8013 -r a9dc1a5115a7 auditok/plotting.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/auditok/plotting.py Mon Aug 26 20:55:16 2019 +0200 @@ -0,0 +1,29 @@ +import matplotlib.pyplot as plt +import numpy as np + + +def plot(data, sampling_rate, show=True): + y = np.asarray(data) + ymax = np.abs(y).max() + nb_samples = y.shape[-1] + sample_duration = 1 / sampling_rate + x = np.linspace(0, sample_duration * (nb_samples - 1), nb_samples) + plt.plot(x, y / ymax, c="#024959") + plt.ylim(-3, 3) + if show: + plt.show() + + +def plot_detections(data, sampling_rate, detections, show=True, save_as=None): + + plot(data, sampling_rate, show=False) + if detections is not None: + for (start, end) in detections: + plt.axvspan(start, end, facecolor="g", ec="r", lw=2, alpha=0.4) + + if save_as is not None: + plt.savefig(save_as, dpi=120) + + if show: + plt.show() + return