0
0
Matplotlibdata~10 mins

Area chart with plt.fill_between in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the matplotlib plotting module.

Matplotlib
import matplotlib.[1] as plt
Drag options to blanks, or click blank then click option'
Aplot
Bpyplot
Ccharts
Dgraph
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'pyplot'.
Using 'charts' or 'graph' which are not valid matplotlib modules.
2fill in blank
medium

Complete the code to create a list of x values from 0 to 4.

Matplotlib
x = [[1] for i in range(5)]
Drag options to blanks, or click blank then click option'
Ai*2
Bi-1
Ci
Di+1
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying or adding to 'i' changes the sequence.
Using 'i-1' results in negative numbers.
3fill in blank
hard

Fix the error in the code to fill the area between y1 and y2.

Matplotlib
plt.fill_between(x, y1, [1])
Drag options to blanks, or click blank then click option'
Ay2
By3
Cx
Dy1
Attempts:
3 left
💡 Hint
Common Mistakes
Using y3 which may not be defined.
Using x instead of a y array.
Repeating y1 as both y arrays.
4fill in blank
hard

Fill both blanks to create y1 and y2 lists for the area chart.

Matplotlib
y1 = [i[1]2 for i in x]
y2 = [i[2]1 for i in x]
Drag options to blanks, or click blank then click option'
A*
B+
C-
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or integer division instead of multiplication or addition.
Mixing up the operators for y1 and y2.
5fill in blank
hard

Fill all three blanks to plot the area chart with labels and show it.

Matplotlib
plt.fill_between(x, y1, y2, color='skyblue', alpha=[1])
plt.title('[2]')
plt.show()  # Display the [3]
Drag options to blanks, or click blank then click option'
A0.5
BArea Chart Example
Cplot
D1.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using alpha values outside 0-1 range.
Forgetting to call plt.show() to display the chart.
Setting title to something unrelated.