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 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 = np.arange(-5, 6, 5)
Y = np.arange(-5, 6, 5)
X, Y = np.meshgrid(X, Y)
Z = X**2 - Y**2
ax.plot_wireframe(X, Y, Z, rstride=1, cstride=1)
plt.show()
AA 3D wireframe plot showing a saddle shape
BA 2D line plot of X and Y
CA scatter plot of points
DAn error due to incorrect meshgrid usage
Step-by-Step Solution
Solution:
  1. Step 1: Understand the meshgrid and function

    X and Y create a grid from -5 to 5 with step 5, so points at -5, 0, 5. Z = X^2 - Y^2 forms a saddle shape.
  2. Step 2: Analyze the plot_wireframe call

    Using rstride=1 and cstride=1 plots all grid lines, producing a wireframe of the saddle surface.
  3. Final Answer:

    A 3D wireframe plot showing a saddle shape -> Option A
  4. Quick Check:

    Wireframe of Z = X^2 - Y^2 = saddle shape [OK]
Quick Trick: Z = X² - Y² creates a saddle; wireframe shows surface shape [OK]
Common Mistakes:
  • Thinking meshgrid creates error
  • Confusing wireframe with scatter or 2D plot
  • Ignoring the shape of Z function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes