Matplotlib极坐标图的反向径向轴

时间:2017-03-29 01:21:04

标签: python matplotlib plot reverse astronomy

我正在尝试创建一个天文极坐标图,其径向轴从外线-45°开始,并在图的中心增加到90°。但我没有找到任何方法来反转PolarAxes实例的径向轴。 invert_yaxis()方法根本不起作用。此外,还有一些隐藏的方法,例如ax.set_rlim()没有任何文档。

这是我目前的代码:

fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.8,0.8], polar=True)
# ax.invert_yaxis()
ax.set_theta_zero_location('N')
ax.set_ylim(-45, 90)
ax.set_yticks(np.arange(-45, 90, 15))
ax.plot(ras, decs, linestyle='', marker='.')

和我的情节

2 个答案:

答案 0 :(得分:1)

它有点“hacky”,但是如果你知道边界(它看起来像你对应于赤纬那样)你可以做类似的事情:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.8,0.8], polar=True)
# ax.invert_yaxis()
ax.set_theta_zero_location('N')
ax.set_rlim(90, -45, 1)
# Note: you must set the end of arange to be slightly larger than 90 or it won't include 90
ax.set_yticks(np.arange(-45, 91, 15))
ax.set_yticklabels(ax.get_yticks()[::-1])
ax.plot([0,10,20], 90-np.array([12,13,14]), linestyle='', marker='.')
fig.show()

enter image description here

答案 1 :(得分:0)

古老的问题,但我终于找到一个简单的答案。使用ax.set_rlim(bottom=90, top=-45)。请注意,您必须在调用ax.plot()之前进行设置,否则它不会相应地变换绘制的点。