A. scatter function does not accept three arguments
B. The lists for x, y, z have different lengths
C. plt.figure() is not imported correctly
D. Missing projection='3d' in add_subplot, so 3D plotting fails
Solution
Step 1: Check subplot creation for 3D
The code uses fig.add_subplot(111) without projection='3d', so it creates a 2D axes.
Step 2: Understand scatter with 3D data
On 2D axes, passing three lists to scatter will treat the third list as point sizes instead of z-coordinates, producing a 2D scatter plot rather than 3D.
Final Answer:
Missing projection='3d' in add_subplot, so 3D plotting fails -> Option D
Quick Check:
3D scatter needs projection='3d' [OK]
Hint: Always add projection='3d' for 3D plots [OK]
Common Mistakes:
Forgetting projection='3d' in add_subplot
Thinking scatter can't take three arguments
Assuming list length mismatch causes error
5. You want to plot a 3D scatter plot with points colored by their z-value using a colormap. Which code snippet correctly achieves this?
hard
A. ax.scatter(x, y, z, c='z', colormap='viridis')
B. ax.scatter(x, y, z, color='z', cmap='viridis')
C. ax.scatter(x, y, z, c=z, cmap='viridis')
D. ax.scatter(x, y, z, colors=z, cmap='viridis')
Solution
Step 1: Understand color mapping in scatter
To color points by a variable, pass that variable to c= and specify cmap for colormap.
Step 2: Check correct parameter names
c is correct for colors; color or colors with string 'z' or colormap are incorrect.
Final Answer:
ax.scatter(x, y, z, c=z, cmap='viridis') -> Option C
Quick Check:
Use c=variable and cmap='name' for color mapping [OK]
Hint: Use c=values and cmap='name' to color points [OK]