简体   繁体   中英

Interpolating between curves using SciPy

Here is my plot:

阴谋

The existing curves are functions obtained using interp1d and I have the raw data as well.

How can I extrapolate to get a curve for 71.5 and interpolate to get a curve for 44.3 using SciPy?

You could interpolate between the two closest curves with weights depending on the value differences. The weights should sum to 1. For the extrapolation, the furthest away curve will have a negative weight.

The code supposes the same number of x and y values for each curve.

import matplotlib.pyplot as plt
import numpy as np

c30 = np.array([[29.58, 10992.90], [34.06, 10488.35], [36.53, 10166.76], [38.92, 9836.60], [41.99, 9298.52], [45.13, 8708.54], [47.68, 8153.57], [49.34, 7768.64], [50.30, 7546.69]])
c45 = np.array([[26.79, 10598.67], [28.89, 10282.69], [30.99, 9962.94], [33.09, 9622.18], [35.18, 9220.9], [37.28, 8773.75], [39.38, 8311.88], [41.48, 7836.1], [43.58, 7344.26]])
c60 = np.array([[24.44, 9518.93], [25.81, 9231.69], [27.17, 8919.78], [28.54, 8576.69], [29.9, 8213.69], [31.27, 7841.51], [32.64, 7437.91], [34., 7004.48], [35.37, 6569.1]])

plt.plot(c30[:, 0], c30[:, 1], color='dodgerblue', label='30')
plt.plot(c45[:, 0], c45[:, 1], color='limegreen', label='45')
plt.plot(c60[:, 0], c60[:, 1], color='crimson', label='60')

c44_3 = ((44.3 - 30) * c45 + (45 - 44.3) * c30) / (45 - 30)
c71_5 = ((71.5 - 45) * c60 + (60 - 71.5) * c45) / (60 - 45)

plt.plot(c44_3[:, 0], c44_3[:, 1], color='orange', label='44.3')
plt.plot(c71_5[:, 0], c71_5[:, 1], color='purple', label='71.5')
plt.legend()
plt.show()

结果图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM