title: stretching curve to reach point python
body: <p>I have a curve and I want to fix the starting point and drag the end point to the blue dot while maintaining the the general shape of the curve (stretching and contracting it). Any thoughts how I might do this?</p>
  <pre><code>import matplotlib.pyplot as pl
  import numpy as np
  
  x = np.linspace(1, 10)
  
  def f(x):
      return np.sin(x) + np.random.normal(scale=0.1, size=len(x))
  
  pl.plot(x, f(x))
  
  pl.plot(8,.2,'bo')
  </code></pre>
  <p><a href="https://i.stack.imgur.com/KRqJf.png" rel="nofollow noreferrer">Curve with Point</a></p>
  <h1>ANSWER</h1>
  <pre><code>
  #shift the end point to the dot
  shift_x = 10-x[-1]
  shift_y = .2-y[-1]
  
  
  #shift the data
  x=x+shift_x
  y=y+shift_y
  
  pl.plot(x,y)
  pl.plot(10,.2,'bo')
  </code></pre>
  <p><a href="https://i.stack.imgur.com/rZdNP.png" rel="nofollow noreferrer">shift end point to desired location</a></p>
  <pre><code>
  #shift the data back to the original points based on how close it is
  #to the end point
  gradient_x = shift_x/len(x)
  gradient_y = shift_y/len(y)
  
  for i in range(len(x)):
      y[i] = y[i]-(len(x)-i)*gradient_y
      x[i] = x[i]-(len(x)-i)*gradient_x
  
  pl.plot(x,y)
  pl.plot(10,.2,'bo')
  </code></pre>
  <p><a href="https://i.stack.imgur.com/hjEGu.png" rel="nofollow noreferrer">All 3 Tranformations</a></p>