0
0
Matplotlibdata~10 mins

Date locators for tick spacing 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 correct date locator for setting tick spacing by days.

Matplotlib
from matplotlib.dates import [1]
Drag options to blanks, or click blank then click option'
AMinuteLocator
BHourLocator
CSecondLocator
DDayLocator
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing HourLocator or MinuteLocator which set ticks by smaller time units.
Using SecondLocator which is for seconds, not days.
2fill in blank
medium

Complete the code to create a date locator that places ticks every 3 days.

Matplotlib
locator = [1](interval=3)
Drag options to blanks, or click blank then click option'
ADayLocator
BMonthLocator
CWeekdayLocator
DHourLocator
Attempts:
3 left
💡 Hint
Common Mistakes
Using MonthLocator which controls ticks by months.
Using WeekdayLocator which is for specific weekdays.
3fill in blank
hard

Fix the error in the code to set major ticks every Monday using the correct weekday locator.

Matplotlib
from matplotlib.dates import WeekdayLocator, MO
locator = WeekdayLocator(byweekday=[1])
Drag options to blanks, or click blank then click option'
AMO
BSU
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers like 0 or 1 instead of the constant MO.
Using SU which is the wrong day.
4fill in blank
hard

Fill both blanks to create a locator that sets ticks every 2 weeks on Wednesday.

Matplotlib
from matplotlib.dates import WeekdayLocator, [1]
locator = WeekdayLocator(byweekday=[2], interval=2)
Drag options to blanks, or click blank then click option'
AWE
BTH
DFR
Attempts:
3 left
💡 Hint
Common Mistakes
Using different weekdays for import and argument.
Using weekdays other than Wednesday.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps dates to values only for dates after January 1, 2020.

Matplotlib
filtered_data = {date: value for date, value in data.items() if date [1] datetime(2020, 1, 1) and value [2] 0 and isinstance(value, [3])}
Drag options to blanks, or click blank then click option'
A>
B>=
Cint
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' which would select wrong dates.
Using wrong type like float instead of int.