matplotlib - Cubic spline interpolation drops out halfway -


i trying make cubic spline interpolation , reason, interpolation drops off in middle of it. it's mysterious , can't find mention of similar occurrences anywhere online.

this dissertation have excluded labels etc. keep obscure intentionally, relevant code follows. context, astronomy related plot.

from scipy.interpolate import cubicspline import numpy np import matplotlib.pyplot plt  w = np.array([0.435,0.606,0.814,1.05,1.25,1.40,1.60]) sum_all = np.array([sum435,sum606,sum814,sum105,sum125,sum140,sum160]) sum_can = np.array([sumc435,sumc606,sumc814,sumc105,sumc125,sumc140,sumc160])  fall = cubicspline(w,sum_all) newallx=np.arange(0.435,1.6,0.001) newally=fall(newallx)  fcan = cubicspline(w,sum_can) newcanx=np.arange(0.435,1.6,0.001) newcany=fcan(newcanx)  #----plot  plt.plot(newallx,newally) plt.plot(newcanx,newcany) plt.plot(w,sum_all,marker='o',color='r',linestyle='') plt.plot(w,sum_can,marker='o',color='b',linestyle='') plt.yscale("log") plt.ylabel("flux s$_v$ [erg s$^-$$^1$ cm$^-$$^2$ hz$^-$$^1$]") plt.xlabel("wavelength [n$\lambda$]") plt.show() 

the plot comes out this, clear gap in interpolation:

img

and in case wondering, these values in sum_all , sum_can arrays (i assume doesn't matter, in case want numbers plot yourself):

sum_all: [  3.87282732e+32   8.79993191e+32   1.74866333e+33   1.59946687e+33    9.08556547e+33   6.70458731e+33   9.84832359e+33] can_all: [  2.98381061e+28   1.26194810e+28   3.30328780e+28   2.90254609e+29    3.65117723e+29   3.46256846e+29   3.64483736e+29] 

the gap happens between [0.606,1.26194810e+28] , [0.814,3.30328780e+28]. if change intervals 0.001 higher, it's obvious plot doesn't break off merely dips below 0 on y-axis (but plot continuous). why that? surely that's not correct interpolation? looking our eyes, that's not well-interpolated connection between 2 points.

any tips or comments extremely appreciated. thank in advance!

the reason breakdown can better observed on linear scale.

enter image description here

we see spline passes below 0, undefined on log scale.

so suggest first take logarithm of data, perform spline interpolation on logarithmically scaled data, , scale 10th power.

from scipy.interpolate import cubicspline import numpy np import matplotlib.pyplot plt  w = np.array([0.435,0.606,0.814,1.05,1.25,1.40,1.60]) sum_all = np.array([  3.87282732e+32,   8.79993191e+32,   1.74866333e+33,   1.59946687e+33,    9.08556547e+33,   6.70458731e+33,   9.84832359e+33]) sum_can = np.array([  2.98381061e+28,   1.26194810e+28,   3.30328780e+28,   2.90254609e+29,    3.65117723e+29,   3.46256846e+29,   3.64483736e+29])  fall = cubicspline(w,np.log10(sum_all)) newallx=np.arange(0.435,1.6,0.001) newally=fall(newallx)  fcan = cubicspline(w,np.log10(sum_can)) newcanx=np.arange(0.435,1.6,0.01) newcany=fcan(newcanx)   plt.plot(newallx,10**newally) plt.plot(newcanx,10**newcany) plt.plot(w,sum_all,marker='o',color='r',linestyle='') plt.plot(w,sum_can,marker='o',color='b',linestyle='') plt.yscale("log")  plt.ylabel("flux s$_v$ [erg s$^-$$^1$ cm$^-$$^2$ hz$^-$$^1$]") plt.xlabel("wavelength [n$\lambda$]") plt.show() 

enter image description here


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

ios - Change Storyboard View using Seague -

verilog - Systemverilog dynamic casting issues -