我有 58 个文件需要绘制。其中一些是空的(不重要,我已经用 if 条件跳过了它们)。我需要使用对数刻度绘制文件中的数据,并带有误差线。我想最后保存情节。我正在使用 Python,spyder。我写了以下代码:
route='/......./'
L=np.arange (1,59, 1)
for i in range (L.shape[0]):
I=L[i]
name_sq= 'Spectra_without_quiescent_'+('{}'.format(I))+'.dat'
Q=np.loadtxt(route+name_sq)
if (len(Q) != 0):
x=Q[:,1]
y=Q[:,2]
z=Q[:,3]
fig=plt.errorbar(x,y,yerr=z, fmt = 'b')
fig.set_yscale('log')
fig.set_xscale('log')
xlabel='Frequency'
ylabel='Flux'
title='Spectrum_'+('{}'.format(I))+'.dat'
name='Spectrum_without_quiescent_'+('{}'.format(I))+'.pdf'
fig.savefig(route+name, fig)
但是,当我运行它时,我收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/media/chidiac/My Passport/DOCUMENTS/My_Publications/2-3C273_radio_spectra/Maximum_flux_code.py", line 49, in <module>
fig.set_yscale('log')
AttributeError: 'ErrorbarContainer' object has no attribute 'set_yscale'
我仍然是 Python 的初学者,我找不到错误,或者如何修复它。非常感谢任何帮助。