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 arrow annotation coordinates
What will be the coordinates of the arrow's start and end points in this plot code?
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([0, 1], [0, 1]) arrow = ax.annotate('', xy=(0.8, 0.8), xytext=(0.2, 0.2), arrowprops=dict(facecolor='blue')) print(f"Start: {arrow.xytext}, End: {arrow.xy}")
Attempts:
2 left
💡 Hint
Remember xytext is the start point and xy is the end point of the arrow.
✗ Incorrect
The arrow starts at xytext=(0.2, 0.2) and points to xy=(0.8, 0.8).
❓ data_output
intermediate2:00remaining
Number of arrows in a plot
Given this code with multiple arrow annotations, how many arrows will be drawn on the plot?
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() for i in range(3): ax.annotate('', xy=(i+1, i+1), xytext=(i, i), arrowprops=dict(facecolor='red')) print(len(ax.texts))
Attempts:
2 left
💡 Hint
Each annotate call adds one arrow annotation.
✗ Incorrect
The loop runs 3 times, each time adding one arrow annotation, so total 3 arrows.
❓ visualization
advanced3:00remaining
Effect of different arrow styles
Which option shows the correct arrow style applied to the annotation?
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([0, 1], [0, 1]) ax.annotate('Point', xy=(0.7, 0.7), xytext=(0.3, 0.3), arrowprops=dict(arrowstyle='->', color='green')) plt.show()
Attempts:
2 left
💡 Hint
The arrowstyle '->' means a simple arrow with a triangular head.
✗ Incorrect
The arrowstyle '->' creates a line with a single triangular arrowhead pointing to the xy point.
🔧 Debug
advanced2:00remaining
Identify the error in arrow annotation code
What error will this code produce when run?
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.annotate('Test', xy=(0.5, 0.5), xytext=(0.2, 0.2), arrowprops=dict(facecolor='red', shrink=1.5)) plt.show()
Attempts:
2 left
💡 Hint
Check the valid range for the 'shrink' parameter in arrowprops.
✗ Incorrect
The 'shrink' parameter must be between 0 and 1. 1.5 is invalid and causes a TypeError.
🚀 Application
expert3:00remaining
Creating a custom curved arrow annotation
Which code snippet correctly creates a curved arrow annotation from (0.1, 0.1) to (0.9, 0.9) with a curved style?
Attempts:
2 left
💡 Hint
The connectionstyle 'arc3,rad=0.3' creates a gentle curved arrow.
✗ Incorrect
Option A uses correct xy and xytext points and a valid connectionstyle with a reasonable curvature radius.