绘图使用matplotlib.imshow将图像与WCS作为x和y轴拟合

时间:2016-06-12 21:45:06

标签: python image matplotlib astropy fits

我想知道是否有人知道如何用python包matplotlib.imshow绘制拟合图像,其中相应的世界坐标系值或者甚至是右上升或下降作为x和y值而不是物理像素值,类似到这个页面的底部图:http://astroplotlib.stsci.edu/page_images.htm

不幸的是,提供的脚本是IDL ......我还不熟悉...

如果我概述了我的gridspec布局,那可能会有所帮助:

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)

但没有运气。

非常感谢。

1 个答案:

答案 0 :(得分:0)

一种解决方案可能是使用subplot parameter to FITSFigure,并从您的gridspec获取边界。

以下几行:

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()

不是很漂亮,但它会起作用。如果我遇到一种更简单的方法将FITSFigure直接附加到轴上,我会修改这个答案或者换一个新答案。

相关问题