Plot a fit

Data plus curve, plt.show.

Scatter the data, overlay the fitted curve, call plt.show().

Goal

Show a line fit and print a, b.

from scipy.optimize import curve_fit
def f(x, a, b):
    return a * x + b
rng = np.random.default_rng(1)
x = np.linspace(0, 10, 25)
y = 2.5 * x + 4 + rng.normal(scale=1.0, size=x.size)
popt, _ = curve_fit(f, x, y)
plt.scatter(x, y, alpha=0.7)
plt.plot(x, f(x, *popt), color='C1')
plt.title('Nairobi mm vs month index')
plt.show()
print(popt.round(3))
x = np.linspace(0, 2 * np.pi, 80)
plt.plot(x, np.sin(x))
plt.show()
print('ok')