简体   繁体   English

使用matplotlib.imshow使用WCS作为x和y轴进行绘图拟合

[英]Plotting fits image with matplotlib.imshow with WCS as x and y axes

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 我想知道是否有人知道如何使用python包matplotlib.imshow绘制适合的图像,并使用相应的世界坐标系值,甚至可能将Right Ascension或Declination作为x和y值,而不是物理像素值,类似于底部此页面的图: http : //astroplotlib.stsci.edu/page_images.htm

Unfortunately, the script provided is in IDL...something I am not yet proficient in... 不幸的是,提供的脚本在IDL中...我还没有精通...

It would probably be helpful if I outlined my gridspec layout: 如果我概述了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)

But to no luck. 但是,没有运气。

Many thanks. 非常感谢。

One solution might be to use the subplot parameter to FITSFigure , and obtain the bounds from your gridspec. 一种解决办法可能是使用的subplot参数FITSFigure从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. 如果我遇到了一种将FITSFigure直接附加到轴上的简便方法, FITSFigure修改此答案或放置一个新答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM