I tried to fit the flux of cosmic rays versus energy for AllParticles&H. I used the CRDB package to extract the data. Then, i used the power law to fit. However, the shape of x is (1236,) and the error in y is (1236,2). how do i fix the shape issue?
Here is my code:
x = t_combined.e
y = t_combined.value
err = t_combined.err_sta
lsq = LeastSquares(x, y, err, power_law)
m = Minuit(lsq, a=1, gamma=-2.0)
plt.errorbar(x, y, err, fmt="o", label="data")
plt.plot(x, (x, *m.values), label="fit") # what does this line do?
ax.scatter(x, y, label="Combined original data", marker="x")
a_fit = minuit.values.a gamma_fit = minuit.values.gamma
x_fit = np.logspace(np.log10(t_combined['e'].min()), np.log10(t_combined['e'].max()), 100) y_fit = power_law(x_fit, a_fit, gamma_fit)
ax.plot(x_fit, y_fit, label="Fitted power law", linestyle='--', color='red')
plt.xlabel(r"𝐸𝑘 [GeV]")
plt.ylabel(r"𝐸𝑘 d𝐽/d𝐸𝑘 [1/(m2 s sr)]")
plt.title('Power Law Fit')
plt.legend()
plt.xscale('log')
plt.yscale('log')
plt.show()
print("Fitted parameters (a, gamma):", m)
plt.show()
x = t_combined.e y = t_combined.value err = t_combined.err_sta ^ SyntaxError: invalid syntax- Please copy, paste and try to run the code you posted to check that it is valid.