极坐标图在matplotlib中给出了错误的角度 [英] Polar plot gives wrong angles in matplotlib

查看:46
本文介绍了极坐标图在matplotlib中给出了错误的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制Python中的右上角-偏角"极坐标图,其中角度表示右上角,半径表示偏角,范围为±30.

我的代码是

  import numpy导入 matplotlib.pyplot 作为 pyplotra = [345.389547454166689,31.892236646759279,45.893722479722229,93.955296573703706,160.079453957685217,211.154701609814822,256.486559377222193,307.258751710462889,299.691923545370344,340.364168244814834,335.077343971296386,358.126565808425dec = [23.835021447037050,25.218513920000003,27.509148433518519,26.551432991388879,-25.077519630833340,-20.134061982500004,-21.042512836851849,-4.903512838240742,-0.506450475370370,14.280932901944448,19.222101837500002,18.792707990无花果= 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()

这将产生以下图形:

很显然,我误解了极坐标图的工作原理,因为RA并不对应于theta = 0时的圆角.例如,我的一个点应具有RA = 45.89度,但似乎没有一个点对应于此

关于我在做什么错的任何建议?

解决方案

情节需要弧度.添加以下行并重新绘制正确显示:

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

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?

解决方案

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

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

这篇关于极坐标图在matplotlib中给出了错误的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆