0

Here is my plot:

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?

ForceBru
  • 43,482
  • 10
  • 63
  • 98

1 Answers1

0

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()

resulting plot

JohanC
  • 71,591
  • 8
  • 33
  • 66
  • Thanks for this. One issue I have: the curves are not linearly spaced. As you can see in the original plot, the horizontal spacing from the 30 curve to the 60 curve is much larger than from the 0 curve to the 30. For that reason I cannot approximate the 71.5 curve purely on the 45 and 60 curves alone. – Jonathan Brent Sep 24 '20 at 21:18
  • You might resample the curves similar to [How to generate equispaced interpolating values](https://stackoverflow.com/questions/19117660/how-to-generate-equispaced-interpolating-values) or [How to redistribute points evenly over a curve](https://stackoverflow.com/questions/18244305/how-to-redistribute-points-evenly-over-a-curve) – JohanC Sep 24 '20 at 21:28