I've got the following simple script that plots a graph:
import matplotlib.pyplot as plt
import numpy as np
T = np.array([6, 7, 8, 9, 10, 11, 12])
power = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])
plt.plot(T,power)
plt.show()
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.
You could use
scipy.interpolate.spline
to smooth out your data yourself:Switching from
spline
toBspline
isn't a straightforward copy/paste and requires a little tweaking:Before:
After:
I presume you mean curve-fitting and not anti-aliasing from the context of your question. PyPlot doesn't have any built-in support for this, but you can easily implement some basic curve-fitting yourself, like the code seen here, or if you're using GuiQwt it has a curve fitting module. (You could probably also steal the code from SciPy to do this as well).
For this example spline works well, but if the function is not smooth inherently and you want to have smoothed version you can also try:
if you increase sigma you can get a more smoothed function.