FAQ: Different Plot Types - Fill Between

This community-built FAQ covers the “Fill Between” exercise from the lesson “Different Plot Types”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

Data Visualization in Python

FAQs on the exercise Fill Between

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

The alpha in plt.fill_between() just sets the transparency, correct? That’s what I saw when I tried different numbers. I was a little confused by the explanation.

2 Likes

From the example set by @lilpuggy in a previous exercise, you can also use numpy arrays instead of list comprehension to solve this:

import numpy as np

#your work here

ax = plt.subplot(1, 1, 1)

plt.plot(range(len(revenue)), revenue)
ax.set_xticks(months)
ax.set_xticklabels(month_names, rotation=30)

y_upper = np.array(revenue) + np.array(revenue)*0.1
y_lower = np.array(revenue) - np.array(revenue)*0.1
plt.fill_between(months, y_lower, y_upper, alpha=0.2)


plt.show()

Cheers! :beer:

3 Likes