【问题标题】:How to draw line segment on FITS figure using APLpy or python 2.7?如何使用 APLpy 或 python 2.7 在 FITS 图形上绘制线段?
【发布时间】:2014-10-31 08:58:22
【问题描述】:

我想在 FITS 图形上画一条连接两点的线段。

这些点的(x,y)坐标是(200,250) & (300,400)。

我为此使用 APLpy。

我的代码是:

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

我正在使用以下网页中描述的 APLpy 的“fig.show_lines()”函数: http://aplpy.readthedocs.org/en/latest/quick_reference.html#shapes

它说“使用 numpy 数组列表”作为 show_lines() 的参数。

但我收到以下错误消息:

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

任何帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: python-2.7 aplpy


    【解决方案1】:

    我知道应该是2xNnumpy数组的列表:

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

    HTH,

    德语。

    【讨论】:

    • 其实我做了一个测试,并没有划清界限。我想看看@astrofrog 对此有何看法。
    【解决方案2】:

    你需要做这样的事情:

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

    x1x2y1y2 的单位是正确的(对我来说这是度数)

    【讨论】:

      【解决方案3】:

      我最近遇到了类似的问题,答案似乎不起作用。您是否尝试过使用

      绘制线条
          matplotlib.pyplot.plot ( usually called as plt.plot)?
      

      这对我有用。

      我使用以下方法打开了一个图形对象:

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

      然后干脆做了:

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

      而且效果很好。我什至不必使用 RA 和 Dec,而是直接使用了使用 astropy 的 all_world2pix() 获得的像素坐标。我很确定 aplpy 有一个等价物,但我从未尝试过。

      【讨论】:

        猜你喜欢
        • 2014-06-16
        • 1970-01-01
        • 1970-01-01
        • 2013-10-30
        • 1970-01-01
        • 1970-01-01
        • 2012-04-11
        • 2019-05-03
        • 2021-11-12
        相关资源
        最近更新 更多