Matplotlib subplots inside a for loop
<p>I have a function that takes in as input, 3 arrays and a constant value.</p>

<p>Inside the function I am giving 10 different arrays with conditions and trying to plot them in 10 different subplots. </p>

<pre><code>def ra_vs_dec(alpha,delta,zphot,mlim):
    zmin = [0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2]
    zmax = [0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3]
    plot_no = [1,2,3,4,5,6,7,8,9,10] # THESE ARE THE SUBPLOT NUMBERS

    for a,b,c in zip(zmin,zmax,plot_no):
        ra = alpha[(data_m200&gt;mlim)*(data_z&gt;a)*(data_z&lt;b)] # RA FOR ZCOSMO
        dec = delta[(data_m200&gt;mlim)*(data_z&gt;a)*(data_z&lt;b)] # DEC FOR ZCOSMO
        ra_zphot = alpha[(data_m200&gt;mlim)*(zphot&gt;a)*(zphot&lt;b)] # RA FOR ZPHOT
        dec_zphot = delta[(data_m200&gt;mlim)*(zphot&gt;a)*(zphot&lt;b)] # DEC FOR ZPHOT

        fig = plt.figure()
        ax = fig.add_subplot(2,5,c)
        ax.scatter(ra,dec,color='red',s=5.0,label=''+str(a)+'&lt;zcosmo&lt;'+str(b)+'')
        ax.scatter(ra_zphot,dec_zphot,color='blue',s=5.0,label=''+str(a)+'&lt;zphot&lt;'+str(b)+'')
        ax.legend(loc='best',scatterpoints=2)

    fig.show()
</code></pre>

<p>However, when I run the above code, <strong>I am getting only the final subplot, i.e the 10th subplot. What I am doing wrong here?</strong> </p>

<p><strong>I would like to see all the 10 subplots.</strong> </p>