comparison auditok/plotting.py @ 249:a9dc1a5115a7

Add plotting.py
author Amine Sehili <amine.sehili@gmail.com>
date Mon, 26 Aug 2019 20:55:16 +0200
parents
children a9f4adfae459
comparison
equal deleted inserted replaced
248:c422eeff8013 249:a9dc1a5115a7
1 import matplotlib.pyplot as plt
2 import numpy as np
3
4
5 def plot(data, sampling_rate, show=True):
6 y = np.asarray(data)
7 ymax = np.abs(y).max()
8 nb_samples = y.shape[-1]
9 sample_duration = 1 / sampling_rate
10 x = np.linspace(0, sample_duration * (nb_samples - 1), nb_samples)
11 plt.plot(x, y / ymax, c="#024959")
12 plt.ylim(-3, 3)
13 if show:
14 plt.show()
15
16
17 def plot_detections(data, sampling_rate, detections, show=True, save_as=None):
18
19 plot(data, sampling_rate, show=False)
20 if detections is not None:
21 for (start, end) in detections:
22 plt.axvspan(start, end, facecolor="g", ec="r", lw=2, alpha=0.4)
23
24 if save_as is not None:
25 plt.savefig(save_as, dpi=120)
26
27 if show:
28 plt.show()
29 return