changeset 309:0ea9521c80d8

Fix issue with plot when signal is zero
author Amine Sehili <amine.sehili@gmail.com>
date Sat, 12 Oct 2019 18:11:13 +0100
parents bc963239143f
children 323a662227ee
files auditok/plotting.py
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/plotting.py	Sat Oct 12 16:23:17 2019 +0100
+++ b/auditok/plotting.py	Sat Oct 12 18:11:13 2019 +0100
@@ -82,18 +82,18 @@
     plot_theme = theme.get("plot", {})
     plot_fc = plot_theme.get("facecolor", plot_theme.get("pfc"))
     for sid, samples in enumerate(y, 1):
-
         ax = fig.add_subplot(nb_subplots, 1, sid)
         ax.set_facecolor(plot_fc)
         if scale_signal:
-            mean = samples.mean()
             std = samples.std()
-            samples = (samples - mean) / std
-            max_ = samples.max()
-            plt.ylim(-1.5 * max_, 1.5 * max_)
-
+            if std > 0:
+                mean = samples.mean()
+                std = samples.std()
+                samples = (samples - mean) / std
+                max_ = samples.max()
+                plt.ylim(-1.5 * max_, 1.5 * max_)
         if amplitude_threshold is not None:
-            if scale_signal:
+            if scale_signal and std > 0:
                 amp_th = (amplitude_threshold - mean) / std
             else:
                 amp_th = amplitude_threshold