import astropy.units as u
import numpy as np
from astropy.io import fits
from astropy.wcs import WCS
import matplotlib.pyplot as plt
from astropy.visualization import simple_norm
from astropy.coordinates import SkyCoord, Galactic
file = "hi4pi-hvc-vlsr-gal-car.fits"
hdul = fits.open(file)
hdr = hdul[0].header
data = hdul[0].data
wcs = WCS(hdr)
norm = simple_norm(data, "linear")
# Plot image on axes ax
fig, ax = plt.subplots(figsize=(10, 6), subplot_kw={"projection": wcs})
cmap = plt.get_cmap("RdBu", 20)
im = ax.imshow(data, cmap=cmap)
ax.set_xlabel("Galactic Longitude")
ax.set_ylabel("Galactic Latitude")
overlay = ax.get_coords_overlay("icrs")
major_ticks = np.arange(0, 360, 30)
#ax.set_xticks(major_ticks)
overlay.grid(color="grey", ls="dotted")
plt.colorbar(im, orientation="horizontal")
plt.savefig("area.png", dpi=300, bbox_inches="tight")
plt.show()
I want to set the RA grid to np.arange(0,360,30)
, a 30 degrees interval instead of 90 degrees interval.
and the dec
label on the right is better to be Dec
but I have no idea how to change it.
the fits file is here: Westmeier 2018
WCS Keywords
Number of WCS axes: 2
CTYPE : 'GLON' 'GLAT'
CRVAL : np.float64(180.000000024) np.float64(0.0)
CRPIX : np.float64(2162.0) np.float64(1080.0)
PC1_1 PC1_2 : np.float64(1.0) np.float64(0.0)
PC2_1 PC2_2 : np.float64(0.0) np.float64(1.0)
CDELT : np.float64(-0.0833333333) np.float64(0.0833333333)
NAXIS : 4323 2144
I don't know how to set the grid intervals of overlay.grid
. I checked the documentation but there seems to not have any functions.
You can access the CoordinateHelper
instances (axis objects) of the overlay by index:
overlay = ax.get_coords_overlay("icrs")
overlay.grid(color="grey", ls="dotted")
overlay[1].set_axislabel('Dec')
overlay[0].set_ticks(np.arange(0, 360, 30) * u.deg)
Another example: https://docs.astropy.org/en/stable/visualization/wcsaxes/overlaying_coordinate_systems.html