bhjghjh
bhjghjh

Reputation: 917

cubic spline to get smooth python line curve

I need to make a smooth line in python using cubic spline, I followed the scipy tutorial and got a little confused. I used the following code:

import matplotlib.pyplot as plt
from scipy import interpolate

tck = interpolate.splrep(time, ca40Mass)
plt.semilogy(time,ca40Mass,label='$^{40}$Ca')
plt.xlabel('time [s]')
plt.ylabel('fallback mass [$M_\odot$]')
plt.xlim(20,60)
plt.ylim(1.0e-3, 2.0e-1)
plt.legend(loc=3)

and my plot still didn't smooth out, maybe I missed something, please help me fix this. My plot output is this:

enter image description here

Upvotes: 1

Views: 1166

Answers (1)

Daniel
Daniel

Reputation: 42778

You are not using the interpolation.

time_spline = numpy.linspace(min(time),max(time),1000)
ca40Mass_spline = interpolate.splev(time_spline, tck)
plt.semilogy(time_spline, ca40Mass_spline, label='$^{40}$Ca')

Upvotes: 2

Related Questions