Bird
0
0

Why does this code raise an error?

medium📝 Debug Q7 of 15
Matplotlib - 3D Plotting
Why does this code raise an error?
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter([1,2], [3,4])
plt.show()
AAxes3D import is incorrect.
Bscatter requires three coordinate arrays for 3D plots.
Cplt.figure() must include projection='3d'.
Dplt.show() is missing.
Step-by-Step Solution
Solution:
  1. Step 1: Check scatter arguments for 3D

    3D scatter requires x, y, and z coordinate arrays; only two are given.
  2. Step 2: Verify other code parts

    Axes3D import is correct, figure creation is fine, and plt.show() is present.
  3. Final Answer:

    scatter requires three coordinate arrays for 3D plots. -> Option B
  4. Quick Check:

    3D scatter needs x,y,z arrays = B [OK]
Quick Trick: 3D scatter needs three coordinate lists: x, y, and z [OK]
Common Mistakes:
  • Providing only two coordinate arrays for 3D scatter
  • Thinking Axes3D import is wrong
  • Assuming plt.show() is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes