title: Subplotting using for loops
body: <p>I am working on jupyter notebook on presenting some plots. I have looked everywhere for an answer with no luck. I have the following dataset (I'm providing a sample but the original dataset is larger [64 columns and 32 rows]):</p>
  <pre><code>label=['hc','svppa','nfvppa','lvppa']
  
  df ={&quot;id&quot;:list(range(1,21,1)), &quot;label&quot;: list(np.repeat(label, 5)), &quot;col1&quot;:list(np.random.normal(100,10,size=20)), &quot;col2&quot;:list(np.random.normal(100,10,size=20)), &quot;col3&quot;:list(np.random.normal(100,10,size=20)), 
                          &quot;col4&quot;:list(np.random.normal(100,10,size=20)), &quot;col5&quot;:list(np.random.normal(100,10,size=20)), &quot;col6&quot;:list(np.random.normal(100,10,size=20)), &quot;col7&quot;:list(np.random.normal(100,10,size=20))}
  df = pd.DataFrame(test_df)
  </code></pre>
  <p>So it looks like this:</p>
  <p><a href="https://i.stack.imgur.com/B4h1T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B4h1T.png" alt="Data Frame.head()" /></a></p>
  <p>Now what I want to do is to plot the probability plots to test for normality using:</p>
  <pre><code>columns = list(master_df.columns[2:])
  for col in columns:
      for label in labels:
          stats.probplot(df[df['label']==label][col], dist='norm', plot=plt)
          plt.title(&quot;Probability plot &quot; + col + &quot; - &quot; + label)
          plt.show()
  </code></pre>
  <p>Which creates the plots that I want but they are not 'pretty for presentation'. I wanted to use the subplotting function in matplotlib, but it does not produce the results desired. Given that I am using stats.probplot I can't figure out a way to properly use subplots.</p>
  <p>I have tried the following (and different iterations) with no luck:</p>
  <pre><code>fig, axes = plt.subplots(nrows=len(columns),4 , figsize= (15,15), sharex=True, sharey=True )
  plt.subplots_adjust(hspace=0.5)
  axes=axes.ravel()
  
  for n, label in enumerate(label):
      for col in columns:
          b = stats.probplot(df[df['label']==label][col], dist='norm', plot=plt(axes[n]))
  </code></pre>
  <p>Any ideas will be much appreciated!</p>