【问题标题】:Reverse radial axes of Matplotlib polar plotMatplotlib极坐标图的反向径向轴
【发布时间】:2017-08-22 07:10:57
【问题描述】:

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

和我的阴谋

【问题讨论】:

标签: python matplotlib plot reverse astronomy


【解决方案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()

【讨论】:

  • 看起来不错,但实际轴仍然相同 - 查看值。所以我们也需要转换它们。
  • 这没有回答问题,点仍然需要在坐标变化下才能以正确的方式打印。
【解决方案2】:

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

【讨论】:

  • 比公认的答案容易得多,而且效果很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-13
  • 1970-01-01
  • 1970-01-01
  • 2010-09-18
  • 1970-01-01
  • 1970-01-01
  • 2014-05-15
相关资源
最近更新 更多