title: Plot several fields in an image
body: <p>How would I plot several FITS fields in a single image ? Each FITS file covers a neighboring part of the sky. </p>
  
  <p>The <code>data</code> field of the HDU only contains the image. So to plot each image at the right coordinates, I need to get information from the <code>header</code> field. But how do I pass that information on the pyplot?</p>
  
  <p>I tried the following, using <code>astropy.WCS</code> so that the information from the headers be used in the plots</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from astropy.io import fits
  from astropy.wcs import WCS
  
  image_files = ['file1.fits', 'file2.fits']
  for image_file in image_files:
      image_header = fits.open(image_file)[0].header  # extract header info
      image_data = fits.getdata(image_file, ext=0)
  
      # use the WCS class to get coordinate info and projection axes to use
      wcs = WCS(image_header)
  
      ax = plt.subplot(projection=wcs)
      im = ax.imshow(image_data, origin='lower')
  </code></pre>
  
  <p>This only shows the last image. </p>
  
  <hr>
  
  <p>I'm expecting something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/0PNno.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0PNno.png" alt="expected result"></a></p>
  
  <p>where both parts of the image come from different fits files which are</p>
  
  <p><a href="https://i.stack.imgur.com/aSVGF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aSVGF.png" alt="file1"></a></p>
  
  <p>and </p>
  
  <p><a href="https://i.stack.imgur.com/8bGfw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8bGfw.png" alt="file2"></a></p>