Complete the code to create a 3D axes object using matplotlib.
import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection=[1])
The correct projection string to create 3D axes is '3d'. It tells matplotlib to create a 3D plot.
Complete the code to plot a 3D scatter plot with points at coordinates (1,2,3).
import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter([1], 2, 3) plt.show()
The scatter method expects numbers or arrays for coordinates. Using 1 as a number is correct for a single point.
Fix the error in the code to correctly set labels for the 3D axes.
import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_xlabel('X axis') ax.set_ylabel('Y axis') ax.[1]('Z axis') plt.show()
The correct method to set the Z axis label in a 3D plot is set_zlabel.
Fill both blanks to create a 3D line plot with points (1,2,3) and (4,5,6).
import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection=[1]) ax.plot([1, 4], [2, 5], [2]) plt.show()
The projection must be '3d' to create 3D axes. The z coordinates for the line plot are [3, 6].
Fill all three blanks to create a 3D surface plot of Z = X^2 + Y^2 over a grid.
import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection=[1]) X = np.linspace(-1, 1, 10) Y = np.linspace(-1, 1, 10) X, Y = np.meshgrid(X, Y) Z = X[2]2 + Y[3]2 ax.plot_surface(X, Y, Z) plt.show()
The projection must be '3d' for 3D plotting. The power operator in Python is **, so X**2 and Y**2 compute squares.