A. plt.axes() should be called on the Figure object
B. plt.axes() creates a new Figure, not Axes
C. plt.figure() must be called after plt.axes()
D. No error, code runs fine
Solution
Step 1: Understand plt.figure() and plt.axes()
plt.figure() creates a Figure and sets it as current. plt.axes() creates Axes in the current Figure using default positioning.
Step 2: Verify code execution
The plot is correctly added to ax and plt.show() displays the figure. The code runs without errors.
Final Answer:
No error, code runs fine -> Option D
Quick Check:
plt.axes() adds to current Figure [OK]
Hint: plt.figure() sets current figure for plt.axes() [OK]
Common Mistakes:
Calling plt.axes() without linking to Figure
Assuming plt.axes() auto-links to last Figure
Calling plt.figure() after plt.axes()
5. You want to create a figure with two side-by-side plots sharing the same y-axis. Which code correctly uses the Figure and Axes model to achieve this?