- Codice:
# fit power law y=a*x**b
def OnFitPowerLaw(self, e):
wave = list(degr)
wave.remove(max(wave))
frat = list(cnt)
frat.remove(max(frat))
x = list(degr)
y = list(cnt)
logA = np.log10(x)
logB = np.log10(y)
from scipy.stats import linregress
slope, intercept, r_value, p_value, std_err = linregress(logA, logB)
offset = intercept*10
# yappr = (slope*logA) + (offset)
b = slope
a = 21.835 #non equivale a offset
yfit = a*((wave)**(-b))
print(slope, offset)
print(r_value**2) # R_square calcolata in modalità logaritmica
fig = plt.figure()
self.ax = fig.add_subplot()
self.ax.set(title='FitPowerLaw')
self.ax.yaxis.grid(linestyle='--')
# self.ax.plot(x, y, "-")
self.ax.scatter(degr, cnt, alpha=0.6)
self.ax.plot(x, yfit, "-")
self.xticks = ( [1, 10, 100, roundup(max(degr), n = 2) ])
self.yticks = ( [1, 10, roundup(max(cnt), n = 1) ])
self.ax.set_xticks(self.xticks)
self.ax.set_yticks(self.yticks)
self.ax.set_xticklabels(self.xticks, fontsize=8)
self.ax.set_yticklabels(self.yticks, fontsize=8)
il valore di
- Codice:
R_square
- Codice:
Slope