在以下几行中,我正在计算数量" chisquare"作为两个变量的函数,a和s:
def getChi(Pa, Ps_theory, Fab_matrix):
chisquare = linalg.transpose(Pa-Ps_theory).dot(Fab_matrix).dot(Pa-Ps_theory)
return chisquare
n = 64
sigma = 3.
key = np.arange(n, dtype=float)
sigma_hat = (float(n)/(2.*np.pi*sigma))
A_list = np.arange(0.1, 0.7, 0.01)
for a in A_list:
for s in np.arange(sigma_hat-3.5, sigma_hat+3.5, 0.01):
Ps_theory = a*np.exp(-(key*key/(2.*s*s)))
chi_square[a,s] = getChi(Pa, Ps_theory, Fab_matrix)
现在我需要在减去最小值后绘制chisquare的等值线图。我试着用以下方式做到这一点:
fig = plt.figure()
ax = figura.add_subplot(111)
ax.set_title('Contour_plots_Chi_square{}'.format(n))
ax.set_xlabel('A')
ax.set_ylabel('sigma')
plt.contour(A_list, np.arange(sigma_hat-3.5, sigma_hat+3.5, 0.01), chi_square)
plt.savefig('chi_square_contour_plot/Chi_square_contour_plot{}.svg'.format(n))
但它不起作用,因为它似乎:
plt.contour(A_list, np.arange(sigma_hat-3.5, sigma_hat+3.5, 0.01), chi_square)
没有遵循正确的语法。有人可以解释一下正确的语法吗?