Categories
Python Answers

How to plot a smooth line with PyPlot and Python?

Spread the love

Sometimes, we want to plot a smooth line with PyPlot and Python.

In this article, we’ll look at how to plot a smooth line with PyPlot and Python.

How to plot a smooth line with PyPlot and Python?

To plot a smooth line with PyPlot and Python, we can use the spline function.

For instance, we write

from scipy.interpolate import spline

xnew = np.linspace(T.min(), T.max(), 300)  

power_smooth = spline(T, power, xnew)

plt.plot(xnew, power_smooth)
plt.show()

to call splint with 300 to let us plot 300 points between T.min() and T.max().

Then we call plot with xnew and power_smooth to plot a smooth plot.

Conclusion

To plot a smooth line with PyPlot and Python, we can use the spline function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *