Skip to content
Advertisement

Plot smooth line with PyPlot

I’ve got the following simple script that plots a graph:

JavaScript

As it is now, the line goes straight from point to point which looks ok, but could be better in my opinion. What I want is to smooth the line between the points. In Gnuplot I would have plotted with smooth cplines.

Is there an easy way to do this in PyPlot? I’ve found some tutorials, but they all seem rather complex.

Advertisement

Answer

You could use scipy.interpolate.spline to smooth out your data yourself:

JavaScript

spline is deprecated in scipy 0.19.0, use BSpline class instead.

Switching from spline to BSpline isn’t a straightforward copy/paste and requires a little tweaking:

JavaScript

Before: screenshot 1

After: screenshot 2

Advertisement