python - 如何在 Matplotlib 中反转轴并设置极坐标图的零位置?

标签 python matplotlib polar-coordinates

使用Matplotlib的极坐标图时,theta轴默认的零位是或向右,角度逆时针增大,如this example所示.

enter image description here

如何指定零位置并反转 theta 增加的方向?截至撰写本文时,documentation相对有限。

最佳答案

轴方法 set_theta_zero_locationset_theta_direction 允许您分别指定零位置和增加 theta 的方向。这是 Matplotlib example 的修改版本.

import numpy as np
import matplotlib.pyplot as plt

r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r

ax = plt.subplot(111, projection='polar')
ax.plot(theta, r)
ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2])  # less radial ticks
ax.set_rlabel_position(-22.5)  # get radial labels away from plotted line
ax.grid(True)

# ---- mod here ---- #
ax.set_theta_zero_location("N")  # theta=0 at the top
ax.set_theta_direction(-1)  # theta increasing clockwise
# ---- mod here ---- #

ax.set_title("A line plot on a polar axis", va='bottom')
plt.show()

enter image description here

请注意,对于 quiverplot,这些方法当前生成 strange results (see GitHub issue) .

关于python - 如何在 Matplotlib 中反转轴并设置极坐标图的零位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49805975/

相关文章:

python - PyYAML与组合,属性错误

python - 当键值在iterable的元素中时,如何使用itertools.groupby?

javascript - 笛卡尔坐标到极坐标导致 NaN

math - 将 3D 极坐标转换为笛卡尔坐标

python - 以 4k (3840*2160) 分辨率缩放 Tkinter GUI?

python - Spark MinMaxScaler 在数据帧上

python - 更新 matplotlib 热图的美观

python - 在使用 Python 的 matplotlib 制作动画期间,第一组(散点)绘图数据保留在图表上

python - 在 Python 中使用 matplotlib 绘制多个图

python - R 轴刻度未显示在极坐标图上