Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
Matplotlib - Real-World Visualization Patterns
What will be the output of this code?
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.annotate('Max', xy=(4, 30), xytext=(3, 35), arrowprops=dict(facecolor='red'))
plt.show()
AA line plot with no annotations visible
BA line plot with an annotation 'Max' pointing to point (4,30) with a red arrow
CA line plot with annotation text 'Max' but no arrow
DSyntax error due to incorrect annotate parameters
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the plot and annotation code

    The code plots points and adds an annotation labeled 'Max' at (4,30) with text at (3,35) and a red arrow.
  2. Step 2: Confirm arrowprops usage

    The arrowprops dict with facecolor='red' correctly draws a red arrow from text to point.
  3. Final Answer:

    A line plot with an annotation 'Max' pointing to point (4,30) with a red arrow -> Option B
  4. Quick Check:

    Annotation with arrow = A line plot with an annotation 'Max' pointing to point (4,30) with a red arrow [OK]
Quick Trick: Arrow appears if arrowprops dict is provided [OK]
Common Mistakes:
  • Expecting no arrow without arrowprops
  • Thinking annotation text appears at point
  • Assuming syntax error due to arrowprops

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes