title: Add trendline with equation in 2D array
body: <p>For understanding, I generated two 2D arrays. After that, I plot the scatter plot of that array. Now I want to draw a linear trendline and also the equation of that line. But I am doing something wrong. I really don't know how to get equation as well.  My code is:</p>
  
  <pre><code># Import Libraries
  import numpy as np
  import matplotlib.pyplot as plt
  
  # Generate Random data 
  a = np.zeros(shape=(8,8))
  a[0] = [1,2,3,4,5,6,7,8]
  a[1] = [1,0,3,4,0,6,6,8]
  a[2] = [1,2,3,4,5,3,7,8]# Import Libraries
  import numpy as np
  import matplotlib.pyplot as plt
  
  # Generate Random data 
  a = np.zeros(shape=(8,8))
  a[0] = [1,2,3,4,5,6,7,8]
  a[1] = [1,0,3,4,0,6,6,8]
  a[2] = [1,2,3,4,5,3,7,8]
  a[3] = [1,2,3,0,5,6,7,8]
  a[4] = [1,2,3,4,5,6,7,5]
  a[5] = [1,2,3,4,5,6,7,8]
  a[6] = [1,2,0,1,5,0,8,8]
  a[7] = [1,2,3,4,5,6,7,8]
  
  b = np.zeros(shape=(8,8))
  b[0] = [1,1,3,4,5,6,7,8]
  b[1] = [1,0,3,4,5,6,7,8]
  b[2] = [1,2,3,4,5,6,5,6]
  b[3] = [2,2,3,0,5,6,7,8]
  b[4] = [1,2,3,8,8,6,7,8]
  b[5] = [1,2,3,4,5,6,7,9]
  b[6] = [1,2,6,4,5,0,7,8]
  b[7] = [1,2,3,4,5,6,7,9]
  
  # Draw scatterplot
  plt.figure();
  plt.title('Scatter plot')
  plt.xlabel('a')
  plt.ylabel('b')
  plt.xlim(0, 10)
  plt.ylim(0, 10)
  plt.scatter(a, b)
  plt.show()
  
  # Add trendline with equation
  #z = np.polyfit(a, b, 1)
  #p = np.poly1d(z)
  #plt.plot(a,p(a),"r--")
  #print "y=%.6fx+(%.6f)"%(z[0],z[1]) #Dont know how it comes!
  </code></pre>
  
  <p>Thanks for help and suggestions!</p>