title: SciPy Monotone Cubic Spline Interpolation
body: <p>I am drawing some graphs in PyQt and I need to use <a href="https://en.wikipedia.org/wiki/Monotone_cubic_interpolation" rel="nofollow noreferrer">monotone cubic spline interpolation</a> to get nice smooth lines (that don't extend their boundries). SciPi has a <code>CubicSpline</code> object which I was able to get working, however it is not "monotonic". Is there an easy way to achieve this? Regretfully my knowledge of math is basic and I really don't know much calculus so reading the documentation has been... unfruitful.</p>
  
  <p>For what it's worth here's my snippet to extrapolate a smoothed spline from a series of data points and plot them into a QRectF:</p>
  
  <pre><code>def range_map(value, from_min, from_max, to_min, to_max):
      left_span = from_max - from_min
      right_span = to_max  - to_min
      value_scaled = float(value - from_min) / float(left_span)
      return to_min + (value_scaled * right_span)
  
  def graph_cubic_spline(dataset, graph_max_x, graph_max_y, plot_rect):
      graphd_points = []
  
      x_vals = range(len(dataset))
      y_vals = dataset
      cs = CubicSpline(x_vals, y_vals, bc_type="natural") # this is obviously where I need to make any modifications
  
      # graph the values on the plot area
      sample_factor = 10
      x_increment = plot_rect.width() / graph_max_x
      for sample in range(((len(dataset) - 1) * sample_factor) + 1):
          index = sample/sample_factor
          x_val = index
          y_val = cs(x_val)
  
          x_pos = (x_increment * x_val) = plot_rect.left()
          y_pos = range_map(y_val, 0, graph_max_y, plot_rect.bottom(), plot_rect.top())
          graphd_points.append((x_pos, y_pos, index))
  
      return graphd_points
  </code></pre>