title: How to fit and plot a linear regression line in python?
body: <p>I have a file contains x, y, and y-err and I simply want to fit a straight line to these data.</p>
  
  <p>This is my original code which I'm plotting the data. based n this I want to fit the straight line:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  #read the data file
  Data = np.loadtxt('dmvals.dat')    
  MJD = Data[:,0]    
  DM = Data[:,1]    
  DM_err = Data[:,2]    
  font = {'family': 'serif',
          'color':  'blue',
          'weight': 'normal',
          'size': 14,
          }
  
  plt.figure()    
  plt.xlabel('time[MJD]', fontdict=font)    
  plt.ylabel('DM[pc/cm^3]', fontdict=font)    
  plt.title('DM values', fontdict=font)    
  plt.errorbar(MJD, DM, DM_err,color='magenta')    
  plt.subplots_adjust(left=0.15 , hspace = 0.5)    
  plt.savefig('dm_variations_plot.png')
  </code></pre>