0
0
Matplotlibdata~10 mins

Arrow annotations 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 add an arrow annotation pointing to (2, 3) with text 'Point'.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 3, 2])
plt.annotate('Point', xy=(2, 3), xytext=(3, 1), arrowprops=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'linestyle': '--'}
B{'color': 'red'}
C{'arrowstyle': '->'}
D{'linewidth': 2}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a dictionary to arrowprops.
Omitting arrowprops entirely, so no arrow appears.
2fill in blank
medium

Complete the code to set the arrow color to blue in the annotation.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([0, 1, 2], [0, 1, 4])
plt.annotate('Max', xy=(2, 4), xytext=(1, 3), arrowprops=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'arrowstyle': '->', 'color': 'blue'}
B{'arrowstyle': '-|>'}
C{'color': 'green'}
D{'linestyle': ':'}
Attempts:
3 left
💡 Hint
Common Mistakes
Setting color outside arrowprops, which has no effect on the arrow.
Using an invalid arrowstyle string.
3fill in blank
hard

Fix the error in the code to correctly display an arrow annotation with a dashed arrow.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 1])
plt.annotate('Down', xy=(3, 1), xytext=(1, 3), arrowprops=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'arrowstyle': '->', 'color': 'red'}
B{'arrowstyle': '-->'}
C{'arrowstyle': '->', 'linestyle': '-.'}
D{'arrowstyle': '->', 'linestyle': '--'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'arrowstyle': '-->' which is invalid.
Setting linestyle outside arrowprops.
4fill in blank
hard

Fill both blanks to create an annotation with a fancy arrow and a shadow.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([0, 1, 2], [0, 2, 1])
plt.annotate('Fancy', xy=(1, 2), xytext=(2, 0), arrowprops=[1], bbox=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A{'arrowstyle': 'fancy', 'color': 'purple'}
B{'boxstyle': 'round,pad=0.5', 'fc': 'yellow', 'ec': 'black', 'lw': 1, 'alpha': 0.5}
C{'boxstyle': 'square', 'fc': 'blue'}
D{'arrowstyle': 'simple', 'color': 'green'}
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing arrowprops and bbox dictionaries.
Using incorrect keys in bbox dictionary.
5fill in blank
hard

Fill all three blanks to create a red arrow annotation with a shadowed text box and a custom arrow width.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.annotate('Custom', xy=(3, 9), xytext=(1, 5), arrowprops=[1], bbox=[2], fontsize=[3])
plt.show()
Drag options to blanks, or click blank then click option'
A{'arrowstyle': '->', 'color': 'red', 'linewidth': 2}
B{'boxstyle': 'round', 'fc': 'lightgrey', 'ec': 'black', 'alpha': 0.7}
C14
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to set linewidth for arrow thickness.
Using string instead of number for fontsize.