'Swap axes in a WCS.
Parameters
wcs : `~astropy.wcs.WCS`
The WCS to have its axes swapped
ax0 : int
ax1 : int
The indices of the WCS to be swapped, counting from 0 (i.e., python
convention, not FITS convention)
Returns
A new `~astropy.wcs.WCS` instance with the same number of axes, but two
swapped'

def swapaxes(self, ax0, ax1):

    inds = list(range(self.wcs.naxis))
    (inds[ax0], inds[ax1]) = (inds[ax1], inds[ax0])
    return self.sub([(i + 1) for i in inds])
