3.1 - Displaying a coordinate layer via the Header

In [6]:
%matplotlib inline
from astropy.wcs import WCS
import numpy as np
from matplotlib.colors import LogNorm
import warnings
warnings.filterwarnings("ignore", category=UserWarning)#delete after also
#warnings.filterwarnings("ignore", category=Warning)#delete after also

#Create WCS object
wcs_for_plot = WCS(image_header)

#prepare plot
fig5 = plt.figure(figsize=(20, 20))
ax = plt.subplot(projection=wcs_for_plot) #add wcs informations on plot
plt.imshow(image_data, origin='lower', cmap='gray', aspect='equal',norm=LogNorm())
plot_title = "Gamma Cassiopae "
plt.title(plot_title ,fontsize=16, loc='left')

#add and configure axis informations
ax = plt.gca()
ax.grid(True, color='white', ls='solid')
ra = ax.coords[0]
dec = ax.coords[1]

ra.set_axislabel('RA (J2000)',  minpad=1)
dec.set_axislabel('DEC (J2000)',  minpad=1)
ra.set_major_formatter('hh:mm:ss.s')
dec.set_major_formatter('dd:mm:ss.s')

#add other grid as overlay
overlay = ax.get_coords_overlay('icrs') # or galactic, alt-az, ...
overlay.grid(True, color='lime', ls='solid')
overlay[0].set_axislabel('RA (deg)')
overlay[1].set_axislabel('DEC (deg)')

#uncomment the line after for show contour on objects
#ax.contour(image_data, transform=ax.get_transform(wcs_for_plot), levels=np.logspace(-3, 0, 3), colors='orange', alpha=1)

#show
plt.show()