import pylab
from scipy import stats
#THIS IS THE CORRECT ONE

# our data
nosleep = [ 32, 38, 48, 24, 46, 35, 30, 34, 42 ]
mistakes = [ 6, 8, 13, 5, 7, 6, 5, 8, 12 ]

# calculate the regression equation
m, b, r, p, std_err = stats.linregress( nosleep, mistakes )
fit = pylab.polyfit( nosleep, mistakes, 1 )
fit_fn = pylab.poly1d( fit )

# plot scatter and regression line
pylab.plot( nosleep, mistakes, 'o', nosleep, fit_fn ( nosleep) )

# add the (written) equation to the plot
equation = "y' = %.3f x %+.3f" % ( m, b )
#pylab.figtext( 0.5, 0.4, equation )

# adjust the graph's details
pylab.xlabel("Hours without sleep")
pylab.ylabel("Numer of Mistakes")
pylab.xlim([20,50])
pylab.ylim([0,14]) 
pylab.show()
3c8c6a1159205e8643ce0e92b25afc4605fded99
<mask token>

<mask token>
pylab.plot(nosleep, mistakes, 'o', nosleep, fit_fn(nosleep))
<mask token>
pylab.xlabel('Hours without sleep')
pylab.ylabel('Numer of Mistakes')
pylab.xlim([20, 50])
pylab.ylim([0, 14])
pylab.show()

<mask token>
nosleep = [32, 38, 48, 24, 46, 35, 30, 34, 42]
mistakes = [6, 8, 13, 5, 7, 6, 5, 8, 12]
m, b, r, p, std_err = stats.linregress(nosleep, mistakes)
fit = pylab.polyfit(nosleep, mistakes, 1)
fit_fn = pylab.poly1d(fit)
pylab.plot(nosleep, mistakes, 'o', nosleep, fit_fn(nosleep))
equation = "y' = %.3f x %+.3f" % (m, b)
pylab.xlabel('Hours without sleep')
pylab.ylabel('Numer of Mistakes')
pylab.xlim([20, 50])
pylab.ylim([0, 14])
pylab.show()

import pylab
from scipy import stats
nosleep = [32, 38, 48, 24, 46, 35, 30, 34, 42]
mistakes = [6, 8, 13, 5, 7, 6, 5, 8, 12]
m, b, r, p, std_err = stats.linregress(nosleep, mistakes)
fit = pylab.polyfit(nosleep, mistakes, 1)
fit_fn = pylab.poly1d(fit)
pylab.plot(nosleep, mistakes, 'o', nosleep, fit_fn(nosleep))
equation = "y' = %.3f x %+.3f" % (m, b)
pylab.xlabel('Hours without sleep')
pylab.ylabel('Numer of Mistakes')
pylab.xlim([20, 50])
pylab.ylim([0, 14])
pylab.show()

import pylab
from scipy import stats
#THIS IS THE CORRECT ONE

# our data
nosleep = [ 32, 38, 48, 24, 46, 35, 30, 34, 42 ]
mistakes = [ 6, 8, 13, 5, 7, 6, 5, 8, 12 ]

# calculate the regression equation
m, b, r, p, std_err = stats.linregress( nosleep, mistakes )
fit = pylab.polyfit( nosleep, mistakes, 1 )
fit_fn = pylab.poly1d( fit )

# plot scatter and regression line
pylab.plot( nosleep, mistakes, 'o', nosleep, fit_fn ( nosleep) )

# add the (written) equation to the plot
equation = "y' = %.3f x %+.3f" % ( m, b )
#pylab.figtext( 0.5, 0.4, equation )

# adjust the graph's details
pylab.xlabel("Hours without sleep")
pylab.ylabel("Numer of Mistakes")
pylab.xlim([20,50])
pylab.ylim([0,14]) 
pylab.show()