0
0
Matplotlibdata~10 mins

Annotation with arrows 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 pyplot module as plt.

Matplotlib
import matplotlib.[1] as plt
Drag options to blanks, or click blank then click option'
Agraph
Bplot
Ccharts
Dpyplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'pyplot' causes import errors.
Using 'charts' or 'graph' are not valid matplotlib modules.
2fill in blank
medium

Complete the code to create a simple plot of y versus x.

Matplotlib
plt.plot(x, [1])
plt.show()
Drag options to blanks, or click blank then click option'
Ay
Bz
Cx
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Passing x twice instead of y.
Passing an undefined variable like z or data.
3fill in blank
hard

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

Matplotlib
plt.annotate('Point', xy=(2, 3), xytext=(3, 4), arrowprops=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'arrowstyle': '->'}
B{'arrow': '->'}
C{'style': '->'}
D{'arrow_type': '->'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'style' or 'arrow' instead of 'arrowstyle' causes the arrow not to appear.
Misspelling the key name.
4fill in blank
hard

Fill both blanks to create an annotation with an arrow pointing from text to a point.

Matplotlib
plt.annotate('Label', xy=[1], xytext=[2], arrowprops={'arrowstyle': '->'})
plt.show()
Drag options to blanks, or click blank then click option'
A(4, 5)
B(2, 3)
C(1, 1)
D(3, 4)
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the xy and xytext coordinates.
Using coordinates outside the plot range.
5fill in blank
hard

Complete the code to create a dictionary comprehension that maps points to their labels only if x > 2.

Matplotlib
labels = {point: label for point, label in points.items() if point[0] [1] 2}
Drag options to blanks, or click blank then click option'
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Adding extra characters between key and colon.
Using wrong comparison operators.