Bird
0
0

What will the following code output?

medium📝 Predict Output Q13 of 15
Matplotlib - Real-World Visualization Patterns
What will the following code output?
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.title('My Plot')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()
AAn error because plt.show() is missing arguments
BA scatter plot with no labels
CA line plot with title 'My Plot' and labeled axes
DA bar chart with default labels
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the plot commands

    The code uses plt.plot() which creates a line plot. It sets title and axis labels.
  2. Step 2: Understand plt.show()

    plt.show() displays the plot with all settings applied.
  3. Final Answer:

    A line plot with title 'My Plot' and labeled axes -> Option C
  4. Quick Check:

    plt.plot() + labels + plt.show() = A [OK]
Quick Trick: plt.plot() + plt.show() displays labeled line plot [OK]
Common Mistakes:
  • Confusing line plot with scatter plot
  • Thinking plt.show() needs arguments
  • Assuming default labels appear without setting them

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes