0
0
Matplotlibdata~10 mins

Why annotations tell the data story in Matplotlib - Test Your Understanding

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

Complete the code to add a title to the plot.

Matplotlib
plt.plot(x, y)
plt.[1]('Sales Over Time')
plt.show()
Drag options to blanks, or click blank then click option'
Atitle
Bxlabel
Cylabel
Dlegend
Attempts:
3 left
💡 Hint
Common Mistakes
Using xlabel or ylabel instead of title.
Forgetting to call plt.show() to display the plot.
2fill in blank
medium

Complete the code to add an annotation pointing to the highest sales point.

Matplotlib
max_index = y.index(max(y))
plt.plot(x, y)
plt.annotate('Peak Sales', xy=(x[max_index], y[max_index]), xytext=(x[max_index], y[max_index]+5), arrowprops={'arrowstyle': '[1]'})
plt.show()
Drag options to blanks, or click blank then click option'
A<-
B-|>
C<->
D->
Attempts:
3 left
💡 Hint
Common Mistakes
Using arrow styles that point backwards or double arrows.
Not setting arrowprops correctly.
3fill in blank
hard

Fix the error in the annotation code by completing the missing parameter.

Matplotlib
plt.plot(x, y)
plt.annotate('Lowest Point', xy=(x[0], y[0]), xytext=(x[0], y[0]-5), [1]={'arrowstyle': '->'})
plt.show()
Drag options to blanks, or click blank then click option'
Atextprops
Barrowprops
Clabel
Dfontsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using textprops instead of arrowprops.
Omitting the arrowprops parameter.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that annotates points with sales above 50.

Matplotlib
annotations = {x: y[1] for x, y in data.items() if y [2] 50}
Drag options to blanks, or click blank then click option'
A**2
B>
C>=
D*2
Attempts:
3 left
💡 Hint
Common Mistakes
Using exponentiation instead of multiplication.
Using less than operators instead of greater than.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that annotates words longer than 3 letters with their uppercase form.

Matplotlib
annotations = { [1]: [2] for word in words if len(word) [3] 3 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values.
Using less than instead of greater than in the condition.