title: Python/Matplotlib: adding regression line to a plot given its intercept and slope
body: <p>Using the following small dataset:</p>
  <pre><code>bill = [34,108,64,88,99,51]
  tip =  [5,17,11,8,14,5]  
  </code></pre>
  <p>I calculated a best-fit regression line (by hand).</p>
  <pre><code>yi = 0.1462*x - 0.8188 #yi = slope(x) + intercept
  </code></pre>
  <p>I've plotted my original data using Matplotlib like this:</p>
  <pre><code>plt.scatter(bill,tip, color=&quot;black&quot;)
  plt.xlim(20,120) #set ranges
  plt.ylim(4,18)
  
  #plot centroid point (mean of each variable (74,10))
  line1 = plt.plot([74, 74],[0,10], ':', c=&quot;red&quot;)
  line2 = plt.plot([0,74],[10,10],':', c=&quot;red&quot;)
  
  plt.scatter(74,10, c=&quot;red&quot;)
  
  #annotate the centroid point
  plt.annotate('centroid (74,10)', xy=(74.1,10), xytext=(81,9),
          arrowprops=dict(facecolor=&quot;black&quot;, shrink=0.01),
          )
  
  #label axes
  plt.xlabel(&quot;Bill amount ($)&quot;)
  plt.ylabel(&quot;Tip amount ($)&quot;)
  
  #display plot
  plt.show()
  </code></pre>
  <p>I am unsure how to get the regression line onto the plot itself. I'm aware that there are plenty of builtin stuff for quickly fitting and displaying best fit lines, but I did this as practice. I know I can start the line at points '0,0.8188' (the intercept), but I don't know how to use the slope value to complete the line (set the lines end points).</p>
  <p>Given that for each increase on the x axis, the slope should increase by '0.1462'; for the line coordinates I tried (0,0.8188) for the starting point, and (100,14.62) for the end point. But this line does not pass through my centroid point. It just misses it.</p>
  <p>Cheers,
  Jon</p>