简体   繁体   English

如何使用 APLpy 或 python 2.7 在 FITS 图上绘制线段?

[英]How to draw line segment on FITS figure using APLpy or python 2.7?

I want to draw a line segment joining two points on a FITS figure.我想在 FITS 图形上绘制一条连接两个点的线段。

(x,y) co-ordinates of these points are (200,250) & (300,400). (x,y) 这些点的坐标是 (200,250) & (300,400)。

I am using APLpy for this.我正在为此使用 APLpy。

My code is:我的代码是:

import matplotlib.pyplot as plt
import aplpy
import numpy as np

fig = aplpy.FITSFigure('test.fits')
fig.show_grayscale()

a=np.ndarray(shape=(2,2))
a[0][0]=200
a[0][1]=250
a[1][0]=300
a[1][1]=400

fig.show_lines(a)

plt.show() 

I am using "fig.show_lines()" function of APLpy described on following web-page: http://aplpy.readthedocs.org/en/latest/quick_reference.html#shapes我正在使用以下网页中描述的 APLpy 的“fig.show_lines()”函数: http ://aplpy.readthedocs.org/en/latest/quick_reference.html#shapes

It says 'use lists of numpy arrays' as argument to show_lines().它说“使用 numpy 数组列表”作为 show_lines() 的参数。

But I got following error message:但我收到以下错误消息:

Traceback (most recent call last):
File "draw.py", line 16, in <module>
fig.show_lines(a)
File "<string>", line 2, in show_lines
File "/home/swapnil/anaconda/lib/python2.7/site-packages/aplpy/decorators.py", line  25, in _auto_refresh
return f(*args, **kwargs)
File "/home/swapnil/anaconda/lib/python2.7/site-packages/aplpy/aplpy.py", line 1275, in show_lines
xp, yp = wcs_util.world2pix(self._wcs, line[0, :], line[1, :])
IndexError: too many indices

Any help will be appreciated.任何帮助将不胜感激。

Thanks.谢谢。

I understand that it should be a list of 2xN numpy arrays:我知道它应该是一个2xN numpy 数组的列表:

x = np.array([[200], [300]])
y = np.array([[250], [400]])

fig.show_lines([x, y])

HTH,哈,

Germán.德语。

You need to do something like this:你需要做这样的事情:

iline = np.array([[x1, x2],[y1,y2]])
fig.show_lines([iline], color = 'r')

Where x1 , x2 , y1 , y2 are in the correct units (for me this was degrees)其中x1x2y1y2的单位正确(对我来说这是度数)

I ran into a similar issue recently and the answers did not seem to work.我最近遇到了类似的问题,答案似乎不起作用。 Have you tried plotting the lines using您是否尝试使用绘制线条

    matplotlib.pyplot.plot ( usually called as plt.plot)?

That did the trick for me.这对我有用。

I opened a figure object using:我使用以下方法打开了一个图形对象:

    fig = aplpy.FITSFigure('fitsfile.fits')

and then simply did:然后简单地做了:

    plt.plot([x1, x2], [y1, y2], color = 'r')

and it worked perfectly well.它工作得很好。 I did not even have to use the RA and Dec and directly used the pixel coordinates obtained from using astropy's all_world2pix().我什至不必使用 RA 和 Dec,而是直接使用通过使用 astropy 的 all_world2pix() 获得的像素坐标。 I'm pretty sure aplpy has an equivalent to that but I never tried it.我很确定 aplpy 有一个等价物,但我从未尝试过。

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

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