Bird
0
0

What will this code display?

medium📝 Predict Output Q5 of 15
Matplotlib - Real-World Visualization Patterns
What will this code display?
import matplotlib.pyplot as plt
before = [2, 4, 6]
after = [3, 5, 7]
labels = ['A', 'B', 'C']
plt.bar(labels, before, color='blue')
plt.bar(labels, after, color='red', alpha=0.5)
plt.show()
ABlue and red bars side-by-side without overlap
BRed bars overlay blue bars with transparency
COnly red bars are visible
DError due to overlapping bars
Step-by-Step Solution
Solution:
  1. Step 1: Understand bar plotting with same x positions

    Bars with same labels overlap; alpha=0.5 makes red bars semi-transparent.
  2. Step 2: Visualize overlay effect

    Red bars overlay blue bars with partial transparency, both visible.
  3. Final Answer:

    Red bars overlay blue bars with transparency -> Option B
  4. Quick Check:

    Same x + alpha < 1 = overlay with transparency [OK]
Quick Trick: Use alpha to see overlapping bars clearly [OK]
Common Mistakes:
  • Expecting side-by-side bars without shifting x
  • Thinking only one color shows
  • Assuming error occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes