Python: Plotting errorbars in a loglog scale, in a loop and then saving the image
<p>I have 58 files that I need to plot. Some of them are empty (not important, I already skipped them with the if condition). I need to plot the data in the files, using a loglog scale, with error bars. And I want to save the plots in the end. 
I am using Python, spyder. 
I have written the following code: </p>

<pre><code>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)
</code></pre>

<p>however, when I run it, I get the following error: </p>

<pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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 &lt;module&gt;
    fig.set_yscale('log')
AttributeError: 'ErrorbarContainer' object has no attribute 'set_yscale'
</code></pre>

<p>I am still a beginner in Python and I couldn't find the error, or how to fix it. 
Any help is very appreciated. </p>