You can install the required packages by doing:
pip install aplpy wcsaxes
APLpy (the Astronomical Plotting Library in Python) is a Python module aimed at producing publication-quality plots of astronomical imaging data in FITS format. The module uses Matplotlib, a powerful and interactive plotting package. It is capable of creating output files in several graphical formats, including EPS, PDF, PS, PNG, and SVG.
APLpy pre-dates Astropy, but has been updated to match requirements to be included as an Astropy-affiliated package.
import aplpy %matplotlib inline import matplotlib.pyplot as plt f = aplpy.FITSFigure('data/msx.fits') f.show_colorscale(vmin=0, vmax=1.e-4, cmap='viridis') f.show_contour('data/msx.fits', colors='black') f.add_grid() plt.show()
/sw/lib/python3.4/site-packages/matplotlib/artist.py:221: MatplotlibDeprecationWarning: This has been deprecated in mpl 1.5, please use the axes property. A removal date has not been set. warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1)
One downside of APLpy is that the ways of customizing figures is not always consistent with the Matplotlib API so it can be a bit confusing in some cases to switch between one and the other. So we have developed a new package called WCSAxes which aims to provide a more consistent user experience. In future, APLpy will be updated to use WCSAxes behind the scenes and will also provide more convenience layers on top of that package.
To make a similar plot to the one above, you would do the following:
from astropy.wcs import WCS wcs = WCS('data/msx.fits') from astropy.io import fits data = fits.getdata('data/msx.fits')
fig = plt.figure(figsize=(8,8)) ax = fig.add_subplot(1, 1, 1, projection=wcs) ax.imshow(data, vmin=0, vmax=1.e-4, origin='lower') ax.grid(color='white', alpha=1, ls='solid') ax.set_xlabel("Galactic Longitude") ax.set_ylabel("Galactic Latitude")