0
0
Matplotlibdata~10 mins

Time series with 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 plot a time series line using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
import pandas as pd

dates = pd.date_range('2024-01-01', periods=5)
values = [10, 12, 9, 14, 13]

plt.plot(dates, [1])
plt.show()
Drag options to blanks, or click blank then click option'
A[10, 12, 9, 14]
Bdates
Crange(5)
Dvalues
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dates' as the y-axis data instead of 'values'.
Using a range or incomplete list instead of the full values list.
2fill in blank
medium

Complete the code to fill the area under the time series line.

Matplotlib
plt.plot(dates, values)
plt.[1](dates, values, alpha=0.3)
plt.show()
Drag options to blanks, or click blank then click option'
Afill
Bfill_between
Cbar
Dscatter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fill' which is not a matplotlib function for this purpose.
Using 'bar' or 'scatter' which create different plot types.
3fill in blank
hard

Fix the error in the code to fill between two time series lines.

Matplotlib
values2 = [8, 11, 10, 13, 12]
plt.plot(dates, values)
plt.plot(dates, values2)
plt.fill_between(dates, values, [1], color='gray', alpha=0.2)
plt.show()
Drag options to blanks, or click blank then click option'
Arange(5)
Bvalues
Cvalues2
Ddates
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dates' or 'range(5)' which are x-axis values, not y-values.
Using the same 'values' list twice, which fills under the same line.
4fill in blank
hard

Fill the blanks to create a dictionary comprehension that maps dates to values only if the value is greater than 10.

Matplotlib
filtered = { [1]: [2] for [3], [4] in zip(dates, values) if [2] > 10 }
Drag options to blanks, or click blank then click option'
Adate
Bvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both key and value.
Not matching variable names in the for loop and the key:value pair.
5fill in blank
hard

Fill the blanks to create a dictionary comprehension that maps uppercase dates (as strings) to values only if the value is less than 13.

Matplotlib
result = { [1]: [2] for [3], [4] in zip(dates, values) if [2] < 13 }
Drag options to blanks, or click blank then click option'
Adate.strftime('%Y-%m-%d').upper()
Bvalue
Cdate
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting the date to string before calling upper().
Using inconsistent variable names.