[英]How to show a confidence interval in python using matplotlib?
I need to show a confidence interval, like in this image:我需要显示一个置信区间,如下图所示:
but I don't know how to do it.但我不知道该怎么做。 I've tried doing lb.fill_between(x, (y1-ci), (y1+ci), color = 'b', alpha = 0.1)
but it returns the error: AttributeError: 'list' object has no attribute 'fill_between'
.我试过做lb.fill_between(x, (y1-ci), (y1+ci), color = 'b', alpha = 0.1)
但它返回错误: AttributeError: 'list' object has no attribute 'fill_between'
.
This is my code:这是我的代码:
import matplotlib.pyplot as plt
x = [10, 100, 1000]
y1 = [215103, 22824279.7, 22063128311]
y2 = [211298.5, 21315505.2, 20563930722]
plt.subplot(2, 2, 1)
ci = 1300
#la = plt.plot(x,y,'b*', label = 'normal')
lb = plt.plot(x,y1, '#FA8072', label = 'LI')
lc = plt.plot(x,y2, '#7FFFD4', label = 'LU')
plt.legend(loc = 'upper left')
plt.title("L1-dcache-loads")
plt.xscale("log")
Thanks in advance!提前致谢!
Use fill_between
like this:像这样使用fill_between
:
plt.figure()
plt.fill_between(x, y1, y2, edgecolor='g', facecolor='g', alpha=0.3)
y1
is your lower bound curve, and y2
is your upper bound curve. y1
是您的下限曲线,而y2
是您的上限曲线。 Output: Output:
In your example:在您的示例中:
plt.figure()
plt.plot(x,y1, '#FA8072', label = 'LI')
plt.fill_between(x, np.array(y1)-ci, np.array(y1)+ci, edgecolor='r', facecolor='r', alpha=0.3)
plt.plot(x,y2, '#7FFFD4', label = 'LU')
plt.fill_between(x, np.array(y2)-ci, np.array(y2)+ci, edgecolor='g', facecolor='g', alpha=0.3)
plt.legend(loc = 'upper left')
plt.title("L1-dcache-loads")
plt.xscale("log")
But the intervals are too small to see.但是间隔太小而看不到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.