title: Matplotlib ValueError: num must be 1 <= num <= 20, not 0
body: <p>I'm following this tutorial of <a href="https://blog.keras.io/building-autoencoders-in-keras.html" rel="nofollow noreferrer">Building Autoencoders in Keras</a> on MNIST handwritten digits.
  Here is the code bellow:</p>
  <pre><code>input_img = Input(shape=(28, 28, 1))  # adapt this if using `channels_first` image data format
  
  x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
  x = MaxPooling2D((2, 2), padding='same')(x)
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
  x = MaxPooling2D((2, 2), padding='same')(x)
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
  encoded = MaxPooling2D((2, 2), padding='same')(x)
  
  # at this point the representation is (4, 4, 8) i.e. 128-dimensional
  
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
  x = UpSampling2D((2, 2))(x)
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
  x = UpSampling2D((2, 2))(x)
  x = Conv2D(16, (3, 3), activation='relu')(x)
  x = UpSampling2D((2, 2))(x)
  decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
  
  autoencoder = Model(input_img, decoded)
  autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
  </code></pre>
  <p>After loading Mnist dataset and train our model, here we are going to plot our original and reconstructed images</p>
  <pre><code>decoded_imgs = autoencoder.predict(x_test)
  
  n = 10
  plt.figure(figsize=(20, 4))
  for i in range(n):
      # display original
      ax = plt.subplot(2, n, i)
      plt.imshow(x_test[i].reshape(28, 28))
      plt.gray()
      ax.get_xaxis().set_visible(False)
      ax.get_yaxis().set_visible(False)
  
      # display reconstruction
      ax = plt.subplot(2, n, i + n)
      plt.imshow(decoded_imgs[i].reshape(28, 28))
      plt.gray()
      ax.get_xaxis().set_visible(False)
      ax.get_yaxis().set_visible(False)
  plt.show()
  </code></pre>
  <p>I searched a lot to fix this problem without finding a solution, here is the error shown bellow:</p>
  <pre><code>    ---------------------------------------------------------------------------
  
  ValueError                                Traceback (most recent call last)
  
  &lt;ipython-input-35-d0a536786436&gt; in &lt;module&gt;()
        5 for i in range(n):
        6     # display original
  ----&gt; 7     ax = plt.subplot(2, n, i)
        8     plt.imshow(x_test[i].reshape(28, 28))
        9     plt.gray()
  
  2 frames
  
  /usr/local/lib/python3.6/dist-packages/matplotlib/axes/_subplots.py in __init__(self, fig, *args, **kwargs)
       64                 if num &lt; 1 or num &gt; rows*cols:
       65                     raise ValueError(
  ---&gt; 66                         f&quot;num must be 1 &lt;= num &lt;= {rows*cols}, not {num}&quot;)
       67                 self._subplotspec = GridSpec(
       68                         rows, cols, figure=self.figure)[int(num) - 1]
  
  ValueError: num must be 1 &lt;= num &lt;= 20, not 0
  
  &lt;Figure size 1440x288 with 0 Axes&gt;
  </code></pre>