顺时针方向的径向文本注释极坐标图

问题描述 投票:0回答:1

我想在极坐标图的半径上放置一些文本。当使用默认的 θ 零位置和方向时,它会按预期工作

fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111, polar=True)
ax.set_yticklabels("")
ax.annotate('test',
            xy=(np.deg2rad(90), 0.5),
            fontsize=15,
            rotation=90)

但是改变方向时会失败

fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111, polar=True)
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
ax.set_yticklabels("")
ax.annotate('test',
            xy=(np.deg2rad(90), 0.5),
            fontsize=15,
            rotation=90)

看起来x和y是正确的,但旋转角度不正确。理论上,顺时针和逆时针之间的变换应该将 theta 变为 -theta,但这显然在这里不起作用。我尝试了任何可能的转变,但似乎发生了一些奇怪的事情..

我错过了什么?

python matplotlib polar-coordinates plot-annotations
1个回答
0
投票

旋转角度将遵循与位置角度相反的方向,从 90 度开始(在位置 0 处,角度为 90°)。此外,您可以使用

angle % 180
来避免文本颠倒:

import matplotlib.pyplot as plt
import numpy as np

angle = 135

fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111, polar=True)
ax.set_theta_zero_location("N") # apply +90° rotation
ax.set_theta_direction(-1)      # set - before angle
ax.set_yticklabels("")
ax.annotate('test',
            xy=(np.deg2rad(angle), 0.5),
            fontsize=15,
            rotation=90-(angle % 180))

plt.show()

angle=135
的输出:

© www.soinside.com 2019 - 2024. All rights reserved.