这是我的问题:
_我有一些物理数据表示 -90 到 90 度之间的角度。存在与此数据相关的已知错误。我正在使用 numpy 和 matplotlib 在 python3 中工作。
_我想为每个测量值绘制带有误差线的数据。角度范围从 -90 到 90,误差不应超出这些范围。例如,对于 85+/-10 度的角度,我希望上部误差条循环回到 -85 而不是转到 95。
_可能吗?如何?我正在尝试使用 $plt.fill_between()$ 或 $plt.errorbar()$,但它不起作用。在上面的示例中,即使我尝试将错误栏强制为 -85,错误也不会循环到 90...
这里有些例子:
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(10) #time
a = np.linspace(50, 89, 10) #fake angle value
e = np.array([10]*10) #error value
a_up = a + e #Upper error bars
a_low = a - e #Lower error bars
f, ax = plt.subplots(nrows=2, ncols=2)
###Simple error graph, I don't want it because error bars outside of [-90, 90]
ax[0, 0].errorbar(t, a, yerr = e) #Plot the errors as error bars
### Same but with shaded area
ax[0, 1].fill_between(t, a_low, a_up) #Plot the errors as filled region
ax[0, 1].plot(t, a, "*r")
###My best option right now, put an upper limit everywhere
for i, u in enumerate(a_up):
if u > 90:
a_up[i] = 90
ax[1, 0].fill_between(t, a_low, a_up) #Plot the errors
ax[1, 0].plot(t, a, "*r")
###Finally, force all errorbars in [-90, 90] (Just for this exemple, it's generalized in my code)
for i, u in enumerate(a_up):
if u >= 90:
a_up[i] -= 90
ax[1, 1].fill_between(t, a_low, a_up) #Plot the errors
ax[1, 1].plot(t, a, "*r")
plt.show()
我希望我足够清楚,我在网上找不到解决方案......也许我不知道如何制定它。
提前感谢您的帮助,在使用您的答案10年后,我终于有机会问一个!:)
狮子座