Bird
0
0

This code tries to plot a large dataset but runs very slowly. What is the main issue?

medium📝 Debug Q14 of 15
Matplotlib - Performance and Large Data
This code tries to plot a large dataset but runs very slowly. What is the main issue?
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 1000000)
y = np.sin(x)
plt.plot(x, y, marker='o')
plt.show()
AUsing markers for every point slows down the plot
BThe <code>linspace</code> function is incorrect
CMissing <code>plt.figure()</code> before plotting
DThe <code>sin</code> function cannot handle large arrays
Step-by-Step Solution
Solution:
  1. Step 1: Identify the plotting parameters causing slowness

    Using marker='o' draws a marker for every point, which is very slow for 1 million points.
  2. Step 2: Understand why other options are incorrect

    linspace and sin work fine with large arrays; plt.figure() is optional here.
  3. Final Answer:

    Using markers for every point slows down the plot -> Option A
  4. Quick Check:

    Markers on millions of points = slow plot = C [OK]
Quick Trick: Avoid markers on every point for big datasets [OK]
Common Mistakes:
  • Blaming data generation functions
  • Thinking figure creation is mandatory here
  • Assuming sin() fails on large arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes