2 part question: through a bunch of cobbled together googling I managed to glue together the code in Python to take a log of a list and plot it against the original list, and apply a linear line of best fit (code below, synthetic data).
How would I go about printing the details for this linear fit (such as the gradient, y-intercept, chi squared) on the graph itself?
How would I modify the code to do the same for a polynomial fit, such as an x^2 line?
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from numpy import exp, loadtxt, pi, sqrt, random, linspace
from lmfit import Model
import glob, os
x=[2,3,5,7,11,13,17,19,23,29,31]
y=np.log10(x)
print(y)
plt.scatter(x, y, label="prime-logs", color="red",
marker="1", s=50)
plt.xlabel('Primes')
plt.ylabel('Log10 Primes')
plt.title('Non-Log Plot of Log Prime v Prime')
plt.legend()
plt.plot(np.unique(x), np.poly1d(np.polyfit(x, y, 1))(np.unique(x)))
plt.show()