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?
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y = np.meshgrid(np.linspace(-1, 1, 10), np.linspace(-1, 1, 10))
Z = np.sin(X) + np.cos(Y)
ax.plot_wireframe(X, Y)
plt.show()
AX and Y are not meshgrid arrays
Bplot_wireframe missing Z argument
CZ calculation uses invalid functions
DAxes3D import is missing
Step-by-Step Solution
Solution:
  1. Step 1: Check plot_wireframe arguments

    plot_wireframe requires X, Y, and Z arrays; here Z is missing.
  2. Step 2: Confirm other parts are correct

    X and Y are meshgrid arrays; Z is correctly calculated; Axes3D is imported.
  3. Final Answer:

    plot_wireframe missing Z argument -> Option B
  4. Quick Check:

    plot_wireframe needs X, Y, and Z arrays [OK]
Quick Trick: Always provide X, Y, and Z to plot_wireframe [OK]
Common Mistakes:
  • Omitting Z argument
  • Confusing meshgrid arrays
  • Missing imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes