0
0
Matplotlibdata~10 mins

Date formatting with mdates 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 date formatter from matplotlib.dates.

Matplotlib
from matplotlib.dates import [1]
Drag options to blanks, or click blank then click option'
ADateFormatter
Bdateparser
CDateLocator
Ddateformat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dateparser' which is not part of matplotlib.dates.
Confusing DateLocator with DateFormatter.
2fill in blank
medium

Complete the code to set the x-axis major formatter to display dates as 'Year-Month'.

Matplotlib
ax.xaxis.set_major_formatter([1]('%Y-%m'))
Drag options to blanks, or click blank then click option'
Amdates.DateFormatter
Bmdates.DateConverter
Cmdates.AutoDateFormatter
Dmdates.DateLocator
Attempts:
3 left
💡 Hint
Common Mistakes
Using DateLocator instead of DateFormatter.
Using AutoDateFormatter which auto-adjusts format but not with a fixed pattern.
3fill in blank
hard

Fix the error in the code to import matplotlib.dates as mdates.

Matplotlib
import matplotlib.[1] as mdates
Drag options to blanks, or click blank then click option'
Adatetime
Bdate
Cdates
Ddateutil
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'date' which is singular and incorrect.
Using unrelated modules like 'datetime' or 'dateutil'.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps dates to formatted strings using DateFormatter.

Matplotlib
formatted_dates = {date: [1]('%Y-%m-%d').format_data(date) for date in dates if date [2] datetime.date(2023, 1, 1)}
Drag options to blanks, or click blank then click option'
Amdates.DateFormatter
Bmdates.DateLocator
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using DateLocator instead of DateFormatter for formatting.
Using '<' which filters dates before Jan 1, 2023.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps date strings to datetime objects parsed with strptime.

Matplotlib
date_dict = [1]([2]: datetime.datetime.strptime([2], '%Y-%m-%d') for [2] in date_strings)
Drag options to blanks, or click blank then click option'
Adict
Bdate_str
Cdate_strings
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list' instead of 'dict' for the container.
Using 'date_strings' as the loop variable which is the list, not the item.