注意
跳到末尾下载完整示例代码。
极坐标轴上的误差条渲染#
在极坐标中绘制误差条图的演示。Theta 误差条是弯曲线,末端带有朝向中心方向的帽。半径误差条是直线,方向朝向中心,带有垂直帽。
import matplotlib.pyplot as plt
import numpy as np
theta = np.arange(0, 2 * np.pi, np.pi / 4)
r = theta / np.pi / 2 + 0.5
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(projection='polar')
ax.errorbar(theta, r, xerr=0.25, yerr=0.1, capsize=7, fmt="o", c="seagreen")
ax.set_title("Pretty polar error bars")
plt.show()

请注意,较大的 theta 误差条将重叠。这可能会降低输出图的可读性。请参见下面的示例图
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(projection='polar')
ax.errorbar(theta, r, xerr=5.25, yerr=0.1, capsize=7, fmt="o", c="darkred")
ax.set_title("Overlapping theta error bars")
plt.show()

另一方面,较大的半径误差条永远不会重叠,它们只会导致数据中不必要的比例,从而减少显示的范围。
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(projection='polar')
ax.errorbar(theta, r, xerr=0.25, yerr=10.1, capsize=7, fmt="o", c="orangered")
ax.set_title("Large radius error bars")
plt.show()

参考资料
此示例中显示了以下函数、方法、类和模块的用法
脚本的总运行时间: (0 分钟 3.959 秒)