Python: numpy.interp giving curved line -
i'm trying linearly interpolate low resolution curve (10 data points) higher resolution (~1000 data points). new curve of same shape many more x , y values, i.e. high , low resolution curves indistinguishable when plotted lines.
i've used numpy's interpolation many times baffles me. usual np.interp(newx, oldx, oldy)
i'm getting funny result when plot it.
the lines between green squares should straight, not arched this.
i'm not sure if matters x values range 0 1000 , y values range 1e-12 1e-16. suggestions appreciated!
update: above plot log log scale happens on linear plot too.
here's actual data. (it's 1e-15 1e-19):
x = array([ 0.3543 , 0.477 , 0.544579, 0.6231 , 0.64142 , 0.7625 , 0.79788 , 0.9134 , 1.02894 , 1.235 , 1.241608, 1.615118, 1.662 , 2.159 , 2.181858, 3.4 , 3.507511, 3.732206, 4.436578, 4.6 , 4.664426, 5.628102, 7.589159, 12. ]) y = array([ 8.54633502e-19, 3.82388943e-18, 7.33750003e-18, 2.98683733e-17, 7.77237551e-17, 2.04059657e-16, 3.72124584e-16, 8.77407275e-16, 1.65824812e-15, 2.48616026e-15, 2.80165491e-15, 2.03270375e-15, 2.03205199e-15, 1.24592352e-15, 1.20231667e-15, 3.85565084e-16, 4.34827044e-16, 3.86967563e-16, 1.67622220e-16, 1.48774069e-16, 1.25065750e-16, 7.53511540e-17, 2.34138998e-17, 5.77852724e-18])
so convinced indeed log scale effect. reason though, when plot using ax.loglog()
, ax.set_yscale('linear')
axis scale changes subplot data doesn't. when plot using ax.plot()
seems fine.
can explain this?
i having same issue scipy's interpolate.interp1d. issue not code, how logarithms work. straight lines on linear plot become curved lines on semilog plot. consider limiting case have 2 points (ya,xa) , (yb,xb) want plot on semilog plot , connect. if first linear interpolation between these points, create object line segment l(x) (represented say, array of finely gridded points). if take log of l , plot vs. x, you'll curved line. gives "bouncy" behavior on attached plot. if want straight line in log plot, you'll need take log of ya , yb, interpolate, plot. if you're looking @ spans multiple decades, you'll want interpolate after taking log, may depend on application.
Comments
Post a Comment