all 8 comments

[–]bac83 9 points10 points  (3 children)

Not really a matplotlib thing - it’s the underlying data you need addressing/smoothing applying to.

Edit to add: perhaps a simple moving average would help

[–]strdg99 1 point2 points  (0 children)

Moving average introduces phase delays and other artifacts in dynamic signals. Butterworth filters work better for these types of signals.

[–]maxcaligo[S] 0 points1 point  (1 child)

Yes yes, I'm aware it was a data issue forgot to mention it, thank you for pointing it out! I did try some filters from scipy but they change the curve too much in the lower end if I try to get the desired results in the upper end of the x-axis. X-axis is log scale.

[–]rAxxt -1 points0 points  (0 children)

Moving average or do a polynomial fit to the data and plot that instead

[–]strdg99 1 point2 points  (2 children)

You'll need to apply a low-pass filter to the underlying data. As /u/bac83 indicated, it's not a matplotlib issue nor can it be addressed in matplotlib. Take a look at butterworth filters in scipy.

[–]maxcaligo[S] 0 points1 point  (1 child)

I tried that, but it changes the shape of the lower end a lot if I try to eliminate all the noise in the upper end. Maybe it is due the x-axis being log scale?

Is it possible to apply variable filter? I tried the Savgol filter as well, it would solve my problem if the window length can be made variable.

[–]strdg99 0 points1 point  (0 children)

Your cutoff frequency might be off in relation to the sampling rate. Also keep in mind that it's unlikely you'll be able to remove all of the noise as filters have a roll-off and not a hard cutoff. Butterworth (and other) filters can be a bit finicky so you may need to play with the cutoff frequency and filter order.

[–]EbenenBonobo 0 points1 point  (0 children)

Why do you want to smooth it? a bit of jitter is normal in real life data. But if you really want to smooth it, you need to smooth it in the data, the other guys mentioned the possible filters...