Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q13 of 15
Matplotlib - Real-World Visualization Patterns
What will be the output of this code snippet?
import matplotlib.pyplot as plt
before = [5, 7]
after = [8, 6]
plt.plot([1, 2], before, label='Before')
plt.plot([1, 2], after, label='After')
plt.legend()
plt.show()
AAn error because plt.plot cannot take two lists
BA bar chart comparing before and after data
CA scatter plot with points at (1,5), (2,7), (1,8), (2,6)
DTwo overlapping line plots showing before and after data
Step-by-Step Solution
Solution:
  1. Step 1: Understand plt.plot with x and y lists

    plt.plot([1, 2], before) plots points (1,5) and (2,7) connected by a line. Similarly for after data.
  2. Step 2: Identify plot type and legend

    Two line plots will appear overlapping on the same axes with labels 'Before' and 'After'. No error occurs.
  3. Final Answer:

    Two overlapping line plots showing before and after data -> Option D
  4. Quick Check:

    plt.plot with x,y lists = line plot [OK]
Quick Trick: plt.plot(x, y) draws lines connecting points [OK]
Common Mistakes:
  • Thinking plt.plot creates bar charts
  • Expecting scatter plot without plt.scatter
  • Assuming plt.plot with two lists causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes