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

8
使用Matplotlib的极坐标图时,theta轴的默认零位置位于右侧,角度逆时针增加,如this example所示。

enter image description here

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

1个回答

11

轴方法set_theta_zero_locationset_theta_direction允许您分别指定零位置和增加theta的方向。下面是Matplotlib示例的修改版本。

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()

这里输入图片描述

请注意,对于箭头图(quiverplot),这些方法目前会产生奇怪的结果(详见GitHub问题)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接