[AstroPy] All-sky plots in astropy

Phil Evans pae9 at leicester.ac.uk
Thu May 5 07:00:57 EDT 2016


Hi,

I'm fairly new to plotting in astropy (indeed, python plotting in 
general), so forgive me if this is basic but: I'm trying to do an 
all-sky plot in astropy/wcsaxes. The problem I have is that the 
Aitoff-plot need two grid lines at RA=0; one of the left of the plot and 
one at the right; however only one is rendering.

A version of the code is below. I can't currently provide the FITS file 
or an image is they contain propretary data, although I can mock 
something else up if needed. The input file is a FITS image with 
RA---AIT and DEC--AIT as the CTYPEs.

Thanks for any help you can give!

Phil

#!/usr/bin/env python
import matplotlib.pyplot as plt
import pyregion
from astropy.io import fits
from astropy.wcs import WCS
from wcsaxes import WCSAxes
from astropy import units as u
import sys

outfile=None
if len(sys.argv)<2:
   print "Usage: skymap.py infile [outfile]"
   sys.exit(1)

infile=sys.argv[1];
if len(sys.argv)>2:
   outfile=sys.argv[2]

hdu=fits.open(infile)[0]

wcs=WCS(hdu.header)
fig=plt.figure()
ax = WCSAxes(fig, [0.0, 0.0, 1.0, 1.0], wcs=wcs)
fig.add_axes(ax)

image=hdu.data

ax.imshow(image, cmap='gray_r', origin='lower', vmin=0, vmax=1e-5,alpha=1.0)


lon=ax.coords['RA']
lat=ax.coords['Dec']
#lon.set_axislabel("RA")
#lat.set_axislabel("Dec")
lon.set_major_formatter('hh:mm:ss')
lon.set_ticks(spacing=30.0*u.degree)
lat.set_ticks(spacing=30.0*u.degree)
lon.grid(color='black', alpha=1.0, linestyle='solid')
lat.grid(color='black', alpha=1.0, linestyle='solid')

r=pyregion.open("sun.reg")
p, text_list = r.get_mpl_patches_texts()
p[0].set_facecolor('#666600')
p[0].set_edgecolor('#666600')
p[0].set_alpha(0.3)
p[0].set_transform(ax.get_transform('fk5'))
ax.add_patch(p[0])

r=pyregion.open("moon.reg")
p, text_list = r.get_mpl_patches_texts()
p[0].set_facecolor('cyan')
p[0].set_edgecolor('cyan')
p[0].set_alpha(0.3)
p[0].set_transform(ax.get_transform('fk5'))
ax.add_patch(p[0])

for ra in [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330] :
   raticklabel = str(ra/15) + '$^h$'
   ax.text(ra, 0, raticklabel, ha='center', 
transform=ax.get_transform("fk5"), color='r')

for dec in [-60, -30, 30, 60]:
   decticklabel = str(dec) + '$^o$'
   ax.text(0, dec, decticklabel, ha='center', 
transform=ax.get_transform("fk5"), color='b')

if outfile!=None:
   plt.savefig(outfile, dpi=144)
else:
   plt.show()





-- 
-------------------------

Phil Evans,
Swift Development Scientist
X-ray and Observational Astronomy Group,
University of Leicester

Tel: +44 (0)116 252 5059
Mobile: +44 (0)7780 980240 (work)
Mobile: +44 (0)7974 977723 (personal)

pae9 at leicester.ac.uk

http://www.star.le.ac.uk/~pae9
http://www.swift.ac.uk

Follow me as a Swift scientist on Twitter: @swift_phil
http://www.star.le.ac.uk/~pae9/twitter



More information about the AstroPy mailing list