2

The astropy documentation has an example on how to plot an image from a FITS file. The axis on the resulting plot correspond to the number of pixels, or data points. I would like the axis to indicate galactic coordinates instead.

Note that the header of my FITS file indicates all of the information regarding the position of the image on the sky. How do I get the plot to show real coordinates rather that number of pixels ?

usernumber
  • 1,958
  • 1
  • 21
  • 58

1 Answers1

3

The WCS framework provided by astropy can be used for plotting with world coordinates.

from astropy.wcs import WCS
from astropy.io import fits
from astropy.utils.data import get_pkg_data_filename
import matplotlib.pyplot as plt

image_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
hdu = fits.open(image_file)[0]
wcs = WCS(hdu.header)

plt.subplot(projection=wcs) 
plt.imshow(hdu.data, origin='lower') 
plt.grid(color='white', ls='solid')
plt.show()
usernumber
  • 1,958
  • 1
  • 21
  • 58