title: Remove margins from a matplotlib figure
body: <p>I'd like to plot a NumPy array using <code>imshow</code> in <code>matplotlib</code> and save it as a JPEG image. However, I can't manage to remove margins/paddings/borders from the image.</p>
  
  <p>My code:</p>
  
  <pre><code>plt.imshow(np.arange(20).reshape(5,4)) ;
  plt.axis('off')
  plt.savefig('test.jpg', bbox_inches='tight', pad_inches=0, facecolor='black')
  </code></pre>
  
  <p>I've followed all recommendations that I could find here on Stackoverflow but none of them would help removing uneven white borders (I made them black in this figure) seen below:</p>
  
  <p><a href="https://i.stack.imgur.com/lMcMG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lMcMG.jpg" alt="enter image description here"></a></p>