# find regession line from dots on graph

import numpy as np
import matplotlib.pyplot as plt
ax = plt.gca()
ax.spines['left'].set_position('zero')  # axis origin x
ax.spines['right'].set_color('blue')
ax.spines['bottom'].set_position('zero') # axis origin y
ax.spines['top'].set_color('red')
plt.xlim([-1, 11])  # range of x,y values
plt.ylim([-1, 11])
plt.grid()
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8])
y = np.array([1, 4, 2, 5, 7, 8, 8, 9, 10])
x_mean= np.mean(x)
y_mean= np.mean(y)
print('x_mean=', x_mean)
m = (np.sum((x_mean)*(y-y_mean)))/(np.sum((x_mean)*(x_mean)))
b = y_mean - m*x_mean
print("m = ",m," b = ",b)
x_line = x
y_line = m*x + b
plt.plot(x_line, y_line, color = "r")
plt.scatter(x, y, color = "g", marker = "o", s = 40) # marrker - type of dot
plt.show()                                           # s - size in pixels
