Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a dictionary to arrowprops.
Omitting arrowprops entirely, so no arrow appears.
✗ Incorrect
The arrowprops parameter requires a dictionary specifying the arrow style, such as {'arrowstyle': '->'} to draw a simple arrow.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting color outside arrowprops, which has no effect on the arrow.
Using an invalid arrowstyle string.
✗ Incorrect
To set the arrow color, include 'color': 'blue' inside the arrowprops dictionary along with the arrow style.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'arrowstyle': '-->' which is invalid.
Setting linestyle outside arrowprops.
✗ Incorrect
To get a dashed arrow, use 'linestyle': '--' inside arrowprops along with 'arrowstyle': '->'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing arrowprops and bbox dictionaries.
Using incorrect keys in bbox dictionary.
✗ Incorrect
Use {'arrowstyle': 'fancy', 'color': 'purple'} for a fancy arrow and a bounding box with shadow using {'boxstyle': 'round,pad=0.5', 'fc': 'yellow', 'ec': 'black', 'lw': 1, 'alpha': 0.5}.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to set linewidth for arrow thickness.
Using string instead of number for fontsize.
✗ Incorrect
Use {'arrowstyle': '->', 'color': 'red', 'linewidth': 2} for a red arrow with thickness, a rounded bbox with light grey fill and transparency, and fontsize 14 for the annotation text.