Python: numpy.interp gives a curved line

I am trying to linearly interpolate a low resolution curve (10 data points) to a much higher resolution (~ 1000 data points). I would like for there to be a new curve of the same shape, but with many other x and y values, that is, the high and low resolution curves would look indistinguishable when plotted as lines.

I used Numpy interpolation many times, so it puzzled me. I do the usual np.interp(newX, oldX, oldY), but I get a funny result when I draw it.

Not linear interpolation

The lines between the green squares should be straight, not arched.

I'm not sure if that matters, but my X values ​​range from 0 to 1000, and my Y values ​​range from 1e-12 to 1e-16. Any suggestions would be greatly appreciated!

: , .

Linear plot, same problem!

. ( 1-15 1-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])

, , . - , , ax.loglog(), do ax.set_yscale('linear') , . ax.plot(), .

- ?

+4
2

, scipy interpolate.interp1d. , , . . , (ya, xa) (yb, xb), . , , L (x) (, , ). L x, . , "" . , ya yb, , . , , , , , .

+2

http://docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,1000,10)
y = np.random.uniform(1e-16, 1e-12, 10)
xvals = np.linspace(0, 1000, 100)
yinterp = np.interp(xvals, x, y)

plt.plot(x, y, c='k')
plt.plot(xvals, yinterp, 'o', c='w')
plt.show()

enter image description here

+1

Source: https://habr.com/ru/post/1542595/


All Articles