Polar plot gives wrong angles in matplotlib

故事扮演 提交于 2019-12-08 04:13:46

问题


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:

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?


回答1:


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

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



来源:https://stackoverflow.com/questions/27216495/polar-plot-gives-wrong-angles-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!