0

Given a curve represented by two arrays with the elements not equally spaced:

x = np.array([ 1.54, 0.73, 0.45, 0.25, 0.18, 0.14, 0.11, 0.10, 0.11, 0.15, 0.37, 0.74 ])
y = np.array([-1., -0.60, -0.39, -0.19, -0.10, 0.01, 0.11, 0.21, 0.31, 0.41, 0.72, 1.])

And the graphic representation:

enter image description here

I want to find the coordinates xi and yi that correspond to the points at position 0.25, 0.50, 0.75.

Is there a straingthforward way to find them in numpyor in matplotlib?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
  • 1
    What exactly do you mean by *ratio*? I can't figure it out from your example. – Jaime Jun 23 '13 at 13:27
  • I mean the normalized position along the curve. `0` is the beginning and `1` the end... – Saullo G. P. Castro Jun 23 '13 at 14:53
  • 1
    voted to close. Question is too vague. There is a partial answer from tcaswell, but because OP doesn't follow-up to clarify, question is still to vague to get a meaningful answer (even though I initially upvoted this question). – tom10 Jun 25 '13 at 17:58
  • @tom10 Please, don't close it because this represents a real problem. The idea came from [this answer here](http://stackoverflow.com/a/17252890/832621) where I am passing to function `rtext()` the data coordinates `x,y` where I want the text to be placed. It would be better passing this normalized coordinate from `0` to `1`... – Saullo G. P. Castro Jun 25 '13 at 18:19

1 Answers1

1

You have to pick some method to interpolate your data. If you have a model to fit your data to, use that, if not scipy has a bunch of tools for interpolating.

This is sort of a non-answer because the best way to do interpolation depends very much on your data and what you want to do with it.

In one sense, your question is ill-defined because say I have a function f(t) -> (x,y) for t in [0, 1), then if I compose f with g(s) -> [0, 1), where g is any monotonic function, then f(g(s)) -> (x,y) is also a valid parameterization of (x,y), but f(0.5) != f(g(0.5)).

tacaswell
  • 84,579
  • 22
  • 210
  • 199