astrofrog / wcsaxes

wcsaxes has been merged into astropy!
http://docs.astropy.org/en/stable/visualization/wcsaxes/index.html
22 stars 21 forks source link

RA axis labels crowded together on all-sky axes #191

Closed lpsinger closed 8 years ago

lpsinger commented 8 years ago

On all-sky axes such as MOL, the RA axis labels are crowded together at the poles. For these sorts of axes, a better option would be to be able draw the labels on a particular line of constant declination.

import astropy.io.fits
import astropy.utils
import astropy.wcs
import wcsaxes
import numpy as np
from matplotlib import pyplot as plt
from reproject import reproject_from_healpix

url = 'https://losc.ligo.org/s/events/GW150914/P1500227/bayestar_gstlal_C01.fits.gz'
filename = astropy.utils.data.download_file(url, cache=True)

header = astropy.io.fits.Header(dict(
    NAXIS=2,
    NAXIS1=360, NAXIS2=180,
    CRPIX1=180, CRPIX2=90,
    CRVAL1=180, CRVAL2=0,
    CDELT1=-2*np.sqrt(2)/np.pi,
    CDELT2=2*np.sqrt(2)/np.pi,
    CTYPE1='RA---MOL',
    CTYPE2='DEC--MOL',
    RADESYS='ICRS').items())
wcs = astropy.wcs.WCS(header)

img, _ = reproject_from_healpix(filename, header)
ax = plt.axes(projection=wcs, frame_class=wcsaxes.frame.EllipticalFrame)
ax.imshow(img, origin='lower', cmap='OrRd')
ax.grid()
plt.savefig('gw151226.png')

gw151226

astrofrog commented 8 years ago

@lpsinger - great idea, and this could be useful even for more normal plots. Would you be interested in working on this? :)

There are currently two ways to plot grid lines - one is by plotting lines directly, and the other is to use contours. In either case, there may be ways built-in to Matplotlib to add text along a path.

lpsinger commented 8 years ago

I'm not sure how to get started. Is there an example that shows how to plot axis labels along arbitrary paths?

astrofrog commented 8 years ago

@lpsinger - I'm not sure either, but in WCSAxes we use the Path class to plot the grid lines by default, so it would be worth checking in the Matplotlib gallery for example if there is a way to plot text that follows paths. I can try and investigate this too, but won't be able to do for the next week or so.

lpsinger commented 8 years ago

Matplotlib's axes base class defines several methods to be defined by subclasses: get_xaxis_transform, get_xaxis_text1_transform, get_xaxis_text2_transform, and the corresponding methods for the y axis. The built-in Matplotlib polar and geographic projections illustrate how these methods control axis label positioning and placement.

However, overriding these methods will probably not work for wcsaxes because the ticks and tick labels are rendered by hand in the Ticks and TickLabels classes. None of the examples in the docs have ticks and tick labels that are inside the frame. Do you have any suggestions for what the API for this should look like?