1

I need to show a confidence interval, like in this image:

enter image description here
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'.
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!

2
  • lb is a list. You need to plt.fill_between. Note that y1-ci will also give you an error Commented Apr 20, 2020 at 14:43
  • @DavidG when i do plt.fill_between I get this error: unsupported operand type(s) for -: 'list' and 'int', just like you said. How can I fix this? Commented Apr 20, 2020 at 14:47

1 Answer 1

1

Use fill_between like this:

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. Output:

bounds

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.

updated

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.