0
0
Matplotlibdata~10 mins

Highlighting date ranges 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 [1].pyplot as plt
Drag options to blanks, or click blank then click option'
Apandas
Bnumpy
Cseaborn
Dmatplotlib
Attempts:
3 left
💡 Hint
Common Mistakes
Importing numpy or pandas instead of matplotlib.
Forgetting to import pyplot submodule.
2fill in blank
medium

Complete the code to create a date range from January 1, 2023 to January 10, 2023 using pandas.

Matplotlib
dates = pd.date_range(start='2023-01-01', end=[1])
Drag options to blanks, or click blank then click option'
A'2023-01-10'
B'2023-01-15'
C'2023-01-05'
D'2023-02-01'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a date outside the desired range.
Using wrong date format.
3fill in blank
hard

Fix the error in the code to highlight the date range between '2023-01-03' and '2023-01-06' on the plot.

Matplotlib
plt.axvspan(pd.to_datetime('2023-01-03'), [1], color='yellow', alpha=0.3)
Drag options to blanks, or click blank then click option'
A'2023-01-06'
Bpd.to_datetime('2023-01-06')
Cdatetime('2023-01-06')
Dpd.date_range('2023-01-06')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing date strings directly without conversion.
Using wrong datetime conversion functions.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each date to its value only if the value is greater than 50.

Matplotlib
highlighted = {date: value for date, value in data.items() if value [1] 50 and date [2] pd.to_datetime('2023-01-05')}
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Mixing up date and value comparisons.
5fill in blank
hard

Fill all three blanks to create a plot with highlighted date ranges and labels.

Matplotlib
plt.plot(dates, values)
plt.axvspan([1], [2], color='green', alpha=0.2)
plt.text([3], max(values), 'Highlight', verticalalignment='bottom')
plt.show()
Drag options to blanks, or click blank then click option'
Apd.to_datetime('2023-01-02')
Bpd.to_datetime('2023-01-07')
Cpd.to_datetime('2023-01-03')
Dpd.to_datetime('2023-01-05')
Attempts:
3 left
💡 Hint
Common Mistakes
Using dates outside the data range.
Placing label outside the plot area.