1

How can I tell which coordinate system is being used in a plot, and how do I specify which coordinate system I want to be used for the overlaying grid ?

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()

How would I specify that I want galactic (or equatorial) coordinates to be used for the plt.grid?

usernumber
  • 1,325
  • 1
  • 9
  • 37

1 Answers1

0

You could do:

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)

fig = plt.figure(figsize=(12,12))
plt.subplot(projection=wcs) 
plt.imshow(hdu.data, origin='lower') 
ax = fig.gca()
overlay = ax.get_coords_overlay('galactic')
overlay.grid(color='red', ls='dotted')
plt.show()

As it is done here. (Did not check the math behind it.)

usernumber
  • 1,325
  • 1
  • 9
  • 37
zabop
  • 3,885
  • 3
  • 14
  • 47