Search code examples
pythonmatplotlibpolar-coordinates

Polar plot gives wrong angles in matplotlib


I am trying to plot a Right Ascension - Declination, polar plot in Python, where the angle denotes the right ascension, and the radius the declination, ranging between ±30.

My code is

import numpy
import matplotlib.pyplot as pyplot

ra = [345.389547454166689,31.892236646759279,45.893722479722229,93.955296573703706,160.079453957685217,211.154701609814822,256.486559377222193,307.258751710462889,299.691923545370344,340.364168244814834,335.077343971296386,358.126565808425880]
dec = [23.835021447037050,25.218513920000003,27.509148433518519,26.551432991388879,-25.077519630833340,-20.134061982500004,-21.042512836851849,-4.903512838240742,-0.506450475370370,14.280932901944448,19.222101837500002,18.792707990925926]   

fig = pyplot.figure()
ax = fig.add_axes([0.1,0.1,0.8,0.8],polar=True)
ax.set_ylim(-30,30)
ax.set_yticks(numpy.arange(-30,30,10))
ax.scatter(ra,dec,c ='r')


pyplot.show()    

This produces the following graph: enter image description here

Clearly I am misunderstanding how a polar graph works, as the RA's do not correspond to the angle round from theta = 0. For example, one of my points should have RA = 45.89 degrees, yet no point seems to correspond to this.

Any advice on what I'm doing wrong?


Solution

  • The plot requires radians. Adding the following line and replotting shows correctly:

    ra  = [x/180.0*3.141593 for x in ra]
    

    enter image description here