0

I was wondering if anyone knew how to plot a fits image with the python package matplotlib.imshow with the corresponding world coordinate system values or perhaps even Right Ascension or Declination as the x and y values rather than the physical pixel values, similar to the bottom plot of this page: http://astroplotlib.stsci.edu/page_images.htm

Unfortunately, the script provided is in IDL...something I am not yet proficient in...

It would probably be helpful if I outlined my gridspec layout:

fig = pyplot.figure(figsize=(11,11))

gridspec_layout = gridspec.GridSpec(3,3)
gridspec_layout.update(hspace=0.0, wspace=0.0)

hdulist_org_M33_UVM2 = fits.open('myfits.fits')
wcs = WCS(hdulist_org_M33_UVM2[0].header)

pyplot_2 = fig.add_subplot(gridspec_layout[2])

ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=wcs)

pyplot_2.add_axes(ax)

But to no luck.

Many thanks.

  • 2
    Have you looked at [APLpy](https://aplpy.github.io)? –  Jun 12 '16 at 22:40
  • @Evert I have indeed. It's not entirely clear how I would implement the tutorial suggestion with a gridspec layout tho...? Would you know how this is done? –  Jun 12 '16 at 22:44
  • @Evert I've updated my question to include my gridspec layout. It just doesn't seem to work with the gridspec module: I receive errors such as "AttributeError: 'AxesSubplot' object has no attribute 'add_axes'" –  Jun 12 '16 at 22:50
  • @Evert Would you know how to implement APLpy within the gridspec layout I have chosen? –  Jun 12 '16 at 23:17
  • I had misunderstood the gridspec part (well, it wasn't in your initial question). But: I don't understand why you create an axes `ax` with `WCSAxes` that seemingly covers the full figure (minus borders), instead of a grid-spec subplot. Do you want to span the figure the full figure (e.g., as a background)? Or do you want to draw the figure in just the one subplot, `gridspec_layout[2]`? –  Jun 13 '16 at 01:58
  • @Evert I'd just like to draw the figure in the gridspec_layout[2] subplot... –  Jun 13 '16 at 07:19

1 Answers1

0

One solution might be to use the subplot parameter to FITSFigure, and obtain the bounds from your gridspec.

Something along the following lines:

from matplotlib import pyplot
from matplotlib import gridspec
import aplpy

fig = pyplot.figure(figsize=(11, 11))
gridspec_layout = gridspec.GridSpec(3, 3)
gridspec_layout.update(hspace=0.0, wspace=0.0)
axes = fig.add_subplot(gridspec_layout[2])
m33 = aplpy.FITSFigure('wfpcii.fits', figure=fig,
                       subplot=list(gridspec_layout[2].get_position(fig).bounds),
                       # dimensions and slices are not normally necessary;
                       # my test-figure has 3 axes
                       dimensions=[0, 1], slices=[0])
print(dir(gridspec_layout[2]))
print(gridspec_layout[2].get_position(fig).bounds)
m33.show_colorscale()
pyplot.show()

Not really pretty, but it'll work. if I come across an easier way to attach a FITSFigure directly to an axes, I'll amend this answer or put a new one.

  • Works really well thank you! Is there a way to edit the font style of the axis labels and the tick fonts? I guess I should look at the APLpy documentation...if you had a link to the best tutorial/guide...? –  Jun 13 '16 at 08:19
  • Also, how would I change colour maps? Would this be done by specifying e.g., cmap='gray' as a aplpy.FITSFigure argument? Or within the show.colorscale() argument? –  Jun 13 '16 at 08:42
  • 1
    That's all in the documentation (the answer to your question is even in the [tutorial](http://aplpy.readthedocs.io/en/stable/quickstart.html)). It might be your worth perusing the documentation a bit more. –  Jun 13 '16 at 09:34
  • Well, APLpy is work in progress; perhaps you're using an older version than what the documentation corresponds to? –  Jun 13 '16 at 23:17
  • Another quick question, how would I set up the figure for EPS quality transparency, I use M33.add_grid() and M33.grid.set_alpha(0.2), and when saving the whole plot to EPS quality, the rasterization I set is not saved...any ideas how I could solve this? –  Jun 15 '16 at 22:25
  • Please don't ask [your question](http://stackoverflow.com/questions/37813267/aplpy-matplotlib-coordinate-grid-alpha-levels-for-eps-quality-figure) in a comment to another question. –  Jun 16 '16 at 00:40