From f512812292de49aef83088b7dfe6a162412c21ba Mon Sep 17 00:00:00 2001 From: Philipp Niedermayer <p.niedermayer@gsi.de> Date: Wed, 25 May 2022 11:24:49 +0200 Subject: [PATCH] Moving average smoothing --- plotting.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plotting.py b/plotting.py index 4e4f1ce..4f55bfd 100644 --- a/plotting.py +++ b/plotting.py @@ -223,8 +223,10 @@ def plot_tune_spectrum(ax, libera_data, xy, turn_range=None, time_range=None, tu if smoothing is not None: ls, = ax.plot(freq, mag, **dict(kwargs, zorder=-100, alpha=0.1)) if 'c' not in kwargs and 'color' not in kwargs: kwargs.update(c=ls.get_color()) - freq, mag, phase = avg(freq, mag, phase, n=smoothing) - + add_scale(ax, smoothing*np.mean(np.diff(freq))) + #freq, mag, phase = avg(freq, mag, phase, n=smoothing) + freq, mag, phase = [scipy.signal.savgol_filter(_, smoothing, 0) for _ in (freq, mag, phase)] # savgol filter with order 0 is moving average + ax.plot(freq, mag, **kwargs) ax.set(xlim=tune_range, xlabel=f'Tune $q_{xy}$', -- GitLab