Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Matplotlib - 3D Plotting
Identify the error in this code snippet:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection=3d)
ax.scatter([1,2],[3,4],[5,6])
plt.show()
Ascatter does not accept three lists
Bprojection=3d should be projection='3d' with quotes
Cplt.figure() is missing parentheses
Dfig.add_subplot should be plt.add_subplot
Step-by-Step Solution
Solution:
  1. Step 1: Check the projection parameter syntax

    The projection value must be a string '3d', so quotes are required.
  2. Step 2: Verify other parts of the code

    scatter accepts three lists, plt.figure() has parentheses, and add_subplot is a method of fig, not plt.
  3. Final Answer:

    projection=3d should be projection='3d' with quotes -> Option B
  4. Quick Check:

    projection string syntax = projection=3d should be projection='3d' with quotes [OK]
Quick Trick: Always quote '3d' in projection parameter [OK]
Common Mistakes:
  • Omitting quotes around '3d'
  • Using plt.add_subplot instead of fig.add_subplot
  • Thinking scatter can't take 3D data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes