Bird
0
0

What will the following code output?

medium📝 Predict Output Q13 of 15
Matplotlib - 3D Plotting
What will the following code output?
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter([1,2], [3,4], [5,6])
print(type(ax))
A<class 'matplotlib.axes._subplots.Axes3DSubplot'>
B<class 'matplotlib.axes._axes.Axes'>
CSyntaxError
DRuntimeError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code creating 3D axes

    The code creates a figure, then adds a 3D subplot with projection='3d'. This returns an Axes3DSubplot object.
  2. Step 2: Check the printed type

    Printing type(ax) will show the class of the 3D axes object, which is Axes3DSubplot.
  3. Final Answer:

    <class 'matplotlib.axes._subplots.Axes3DSubplot'> -> Option A
  4. Quick Check:

    3D subplot type = Axes3DSubplot [OK]
Quick Trick: 3D subplot returns Axes3DSubplot type [OK]
Common Mistakes:
  • Expecting base Axes type
  • Confusing syntax or runtime errors
  • Not importing Axes3D

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes