Bird
0
0

What is wrong with this matplotlib code for a 3D scatter plot?

medium📝 Debug Q6 of 15
Matplotlib - 3D Plotting
What is wrong with this matplotlib code for a 3D scatter plot?
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter([1,2], [3,4], [5,6])
plt.show()
AThe subplot lacks the 'projection="3d"' argument
BThe scatter method cannot take three lists as input
Cplt.figure() should be plt.plot()
DThe lists have different lengths
Step-by-Step Solution
Solution:
  1. Step 1: Check subplot creation

    The subplot is created without specifying 3D projection, so it defaults to 2D.
  2. Step 2: Understand scatter inputs

    Scatter can accept three lists for 3D plots, but only if the axis supports 3D.
  3. Final Answer:

    The subplot lacks the 'projection="3d"' argument -> Option A
  4. Quick Check:

    Always add projection='3d' for 3D plots [OK]
Quick Trick: Add projection='3d' to subplot for 3D plots [OK]
Common Mistakes:
  • Omitting projection='3d' in add_subplot
  • Assuming scatter can't take three coordinate lists
  • Confusing plt.figure() with plt.plot()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes