title: Python interpolation sin function using nearest method
body: <p>I write simple code using interpolation of sin function, nearest method. My question is it's that code it's correct? It seems to me that the function should consist of straight lines. Curved lines appear on the generated graph.</p>
  
  <p><a href="https://i.stack.imgur.com/5JBRi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5JBRi.png" alt="enter image description here"></a></p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.interpolate import interp1d
  import math
  
  # Original "data set" --- 21 random numbers between 0 and 1.
  x0 = np.arange(9)
  y0 = [math.sin(i) for i in x0]
  
  plt.plot(x0, y0, 'o', label='Data')
  plt.grid(linestyle="-", color=(0.7, 0.8, 1.0))
  
  x = np.linspace(0, 8, len(x0)*2)
  
  # Available options for interp1d
  options = ('linear', 'nearest')
  
  f = interp1d(x0, y0, kind='nearest')    # interpolation function
  plt.plot(x, f(x), label='nearest')      # plot of interpolated data
  
  plt.legend()
  plt.show()
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I woudl like to impelment own interpolation algorithm, I try to divide sum of 2 values by 2</p>
  
  <pre><code>lst = list(x0)
  for i, val in enumerate(lst):
      lst[i] = lst[i] + lst[i+1] / 2
  
  x0 = tuple(lst)
  
  plt.plot(x0, y0, label='nearest')
  </code></pre>
  
  <p>But it's not working correctly </p>