编程语言
首页 > 编程语言> > python – Matplotlib极坐标图的反向径向轴

python – Matplotlib极坐标图的反向径向轴

作者:互联网

我正在尝试创建一个天文极坐标图,其径向轴从外线的-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='.')

和我的情节

解决方法:

它有点“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

标签:python,matplotlib,plot,reverse,astronomy
来源: https://codeday.me/bug/20190929/1832319.html