How would I plot several FITS fields in a single image ? Each FITS file covers a neighboring part of the sky.
The data
field of the HDU only contains the image. So to plot each image at the right coordinates, I need to get information from the header
field. But how do I pass that information on the pyplot?
I tried the following, using astropy.WCS
so that the information from the headers be used in the plots
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')
This only shows the last image.
I'm expecting something like this:
where both parts of the image come from different fits files which are
and