title: Cannot save annotated image in matplotlib
body: <p>I have read every SO thread I could find on this topic, and have read the documentation rather extensively, and even copied and pasted code from these questions/tutorials. But I am still unable to load a jpg, annotate it, and save the figure with matplotlib. I really could use some advice on this topic.</p>
  
  <p>Here is an example of one of my many attempts:</p>
  
  <pre><code>import cv2
  import matplotlib.pyplot as plt
  
  image = cv2.imread(...filepath-to-img...)
  fig, ax = plt.subplots()
  ax.imshow(image)
  ax.add_patch(plt.Rectangle(...params...)
  plt.savefig(...filepath...)
  </code></pre>
  
  <p>The image loads correctly, and when I work interactively and run the plt.subplots( and ax.imshow(image) commands, I see a plot with the image pop up, and I get a note saying that it is an AxesImage object.</p>
  
  <p>But when I got to save, it says 'Figure size 432x288 with 0 Axes,' and the resulting image saved to disk is blank.</p>
  
  <p>I've also tried the following for saving to no avail.</p>
  
  <pre><code>my_fig = plt.cgf()
  my_fig.savefig(...filepath...)
  </code></pre>
  
  <p>Basically, it seems that creating a figure and axes, and calling ax.imshow() is not adding the image to my axes, nor are the ax.add_patch() calls doing anything to the axes.</p>
  
  <p>I've also tried it without creating separate axes, as with:</p>
  
  <pre><code>plt.figure()
  plt.imshow(image)
  my_axes = plt.gca()
  my_axes.add_patch(plt.Rectangle(...params...)
  plt.savefig(...filepath...)
  </code></pre>
  
  <p>Again, the resulting figure is blank and has 0 axes.</p>
  
  <p>I know I'm probably missing an obvious step, but I can't figure out what it is, and even copying and pasting code has been no help.</p>
  
  <p><strong>Edit: Adding complete code in response to comment</strong></p>
  
  <pre><code>import cv2
  from matplotlib import pyplot as plt
  
  img = './1.png' # 364x364
  
  image = cv2.imread(img)
  fig, ax = plt.subplots()
  ax.imshow(image)
  
  color = (1, 0, 0, 1)
  ax.add_patch(plt.Rectangle((139, 25), 85, 336,
      color = color,
      fill = False,
      linewidth = 2))
  plt.savefig('./annotated.png')
  </code></pre>