7

我正在寻找一种在 Python 中绘制阴影错误区域而不是错误栏的方法。

我知道matplotlib.pyplot.fill_between()您可以使用它为 y 错误构建解决方法,但这不包括 x 不确定性。

问题描述

有任何想法吗?不幸的是,我没有足够的声誉在这里发表评论。

提前致谢!


编辑

matplotlib.pyplot.fill_betweenx()导致类似:

fill_between_problem1


编辑 2

此外,我认为对于一个完全不确定的区域来说它是不正确的。下面我画了我认为正确的形状 - 我希望,我在这里没有错......

问题草图

import numpy as np
import matplotlib.pyplot as plt

x = np.asarray([1.0, 2.0, 3.0, 4.0])
y = np.asarray([1.0, 2.3, 3.0, 4.0])
xerr = np.asarray([0.1, 0.7, 0.1, 0.1])
yerr = np.asarray([0.1, 0.9, 1.2, 0.1])

plt.errorbar(x, y, yerr, xerr)

plt.fill_between(x, y-yerr, y+yerr, facecolor='#F0F8FF', alpha=1.0, edgecolor='none')
plt.fill_betweenx(y,x-xerr, x+xerr, facecolor='#F0F8FF', alpha=1.0, edgecolor='#8F94CC', linewidth=1, linestyle='dashed')

plt.show()
# Red lines added with inkscape.
4

1 回答 1

8

我得到了这个fill_betweenx函数:

import numpy as np
import matplotlib.pyplot as plt

x = np.asarray([1.0, 2.0, 3.0, 4.0, 5.0])
y = np.asarray([1.0, 2.0, 3.0, 4.0, 5.0])
xerr = np.asarray([0.2, 0.4, 0.6, 0.8, 1.0])
yerr = np.asarray([0.1, 0.2, 0.3, 0.4, 0.5])

plt.errorbar(x, y, yerr, xerr)

plt.fill_between(x, y-yerr, y+yerr,facecolor='r',alpha=0.5)
plt.fill_betweenx(y,x-xerr,x+xerr,facecolor='b',alpha=0.5)

plt.show()  

这导致了这个情节:

填充之间,填充之间x


编辑

在您的具体示例中,使用以下内容可能就足够了:

plt.fill_between(x, y-yerr, y+yerr,facecolor='#F0F8FF',alpha=1.0,edgecolor='none')
plt.fill_betweenx(y,x-xerr, x+xerr,facecolor='#F0F8FF',alpha=1.0,edgecolor='none')

这样,你就没有边缘,它会交叉并放弃这个“折叠”。此外,它可能会产生一个错误带的充分错觉。但是,您必须同时使用fill_betweenand fill_betweenx

于 2014-07-18T12:55:09.553 回答