问题描述
我正在尝试创建一个天文极坐标图,其径向轴从外线上的-45°开始,并在图的中心增加到90°.但是我没有找到任何方法来反转PolarAxes实例的径向轴. invert_yaxis()
方法根本不起作用.另外,有些 hidden 方法(例如ax.set_rlim()
)没有任何文档.
I'm trying to create an astronomical polar plot with a radial axis that starts from -45° on outer line and increases to 90° in the center of the plot. But I didn't find any way to reverse radial axis of the PolarAxes instance. invert_yaxis()
method doesn't work at all. Also, there are some hidden methods such as ax.set_rlim()
that doesn't have any docs.
这是我当前的代码:
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",但是如果您知道界限(看起来像是与磁偏角相对应),则可以执行以下操作:
It's a little bit "hacky", but if you know the bounds (which it seems like you do as it corresponds to declination) you could do something like:
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()
这篇关于Matplotlib极坐标图的反向径向轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!