How to draw line segment on FITS figure using APLpy or python 2.7?
Question: I want to draw a line segment joining two points on a FITS figure.

(x,y) co-ordinates of these points are (200,250) & (300,400).

I am using APLpy for this.

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>

It says 'use lists of numpy arrays' as argument to 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.


Answer: I understand that it should be a list of `2xN` numpy arrays:

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

HTH,

Germán.

