Python 3.x 使用matplotlib选择栅格覆盖的坐标系

Python 3.x 使用matplotlib选择栅格覆盖的坐标系,python-3.x,matplotlib,astropy,Python 3.x,Matplotlib,Astropy,如何确定绘图中使用的坐标系,以及如何指定要用于叠加栅格的坐标系 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') h

如何确定绘图中使用的坐标系,以及如何指定要用于叠加栅格的坐标系

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()
我如何指定希望银河(或赤道)坐标用于
plt.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)

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()
就这样做了。(没有检查后面的数学。)

您可以执行以下操作:

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()
就这样做了。(没有检查背后的数学。)