1

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

bhjghjh
  • 889
  • 3
  • 16
  • 42

1 Answers1

2

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')
Daniel
  • 42,087
  • 4
  • 55
  • 81
  • Hi Daniel, I am getting an error with the ca40Mass_spline = interpolate.splev(time_hi, tck) : time_hi is not defined, could that be time_spline? – bhjghjh Aug 20 '16 at 21:47