Bird
0
0

Identify the error in this code that tries to highlight and annotate a point:

medium📝 Debug Q14 of 15
Matplotlib - Real-World Visualization Patterns
Identify the error in this code that tries to highlight and annotate a point:
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [5, 7, 9]
plt.plot(x, y)
plt.axhspan(6, 8, color='green')
plt.annotate('Important', xy=(2, 7), xytext=(2, 9), arrowprops='->')
plt.show()
Aplt.axhspan should use x values, not y values
Bplt.plot should use scatter instead for annotation
Cxytext coordinates must be inside the plot range
Darrowprops should be a dictionary, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check plt.axhspan usage

    plt.axhspan(6, 8, color='green') is correct to highlight horizontal area between y=6 and y=8.
  2. Step 2: Check plt.annotate arrowprops parameter

    arrowprops must be a dictionary describing arrow style, not a string like '->'.
  3. Final Answer:

    arrowprops should be a dictionary, not a string -> Option D
  4. Quick Check:

    arrowprops = dict(...) not string [OK]
Quick Trick: arrowprops needs dict, not string like '->' [OK]
Common Mistakes:
  • Passing arrowprops as string instead of dict
  • Confusing axhspan with axvspan usage
  • Thinking xytext must be inside plot limits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes