Challenge - 5 Problems
Arrow Annotation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of simple annotation with arrow
What will be the output of this code snippet that creates a plot with an annotation and an arrow?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.annotate('Point 2', xy=(2, 5), xytext=(3, 4), arrowprops=dict(facecolor='blue')) plt.show()
Attempts:
2 left
💡 Hint
Remember that xy is the point being annotated and xytext is where the text and arrow start.
✗ Incorrect
The arrow points from the text location (3,4) to the annotated point (2,5). The arrow color is blue as set by facecolor='blue'.
❓ data_output
intermediate1:30remaining
Coordinates of annotated point and text
Given this code, what are the coordinates of the annotated point and the text position?
Matplotlib
import matplotlib.pyplot as plt plt.plot([0, 1, 2], [0, 1, 4]) plt.annotate('Max', xy=(2, 4), xytext=(1, 3), arrowprops=dict(arrowstyle='->')) plt.show()
Attempts:
2 left
💡 Hint
xy is the point being annotated, xytext is where the text is placed.
✗ Incorrect
The annotation points to (2,4) and the text is placed at (1,3).
❓ visualization
advanced1:30remaining
Effect of different arrow styles
Which arrow style will produce a simple arrowhead with no tail or fancy shapes?
Attempts:
2 left
💡 Hint
Look for the simplest arrow style name.
✗ Incorrect
The '->' style is a simple arrowhead. Others add tails or shapes.
🔧 Debug
advanced2:00remaining
Identify the error in annotation code
What error will this code raise?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.annotate('Label', xy=(2, 5), xytext=(3, 4), arrowprops=dict(color='red')) plt.show()
Attempts:
2 left
💡 Hint
Check the valid keys for arrowprops in matplotlib.
✗ Incorrect
The arrowprops dictionary does not accept 'color'. Use 'facecolor' or 'edgecolor' instead.
🚀 Application
expert2:30remaining
Create annotation with curved arrow
Which code snippet correctly creates an annotation with a curved arrow pointing from text at (1, 1) to point (2, 2)?
Attempts:
2 left
💡 Hint
Remember xy is the point being annotated, xytext is text location. Use correct connectionstyle syntax.
✗ Incorrect
Option B correctly sets xy and xytext and uses valid connectionstyle 'arc3,rad=0.5' for a curved arrow.