0
0
Matplotlibdata~10 mins

3D axes with projection='3d' in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a 3D axes object using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection=[1])
Drag options to blanks, or click blank then click option'
A'3d'
B'xyz'
C'2d'
D'3D'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '3D' instead of '3d' (case sensitive).
Using '2d' which creates a 2D plot.
2fill in blank
medium

Complete the code to plot a 3D scatter plot with points at coordinates (1,2,3).

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter([1], 2, 3)
plt.show()
Drag options to blanks, or click blank then click option'
A'1'
B(1,)
C1
D[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string '1' instead of a number.
Using a list or tuple when a single number is enough.
3fill in blank
hard

Fix the error in the code to correctly set labels for the 3D axes.

Matplotlib
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()
Drag options to blanks, or click blank then click option'
Aset_z_axis
Blabel_z
Cset_z
Dset_zlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like set_z_axis or label_z.
Forgetting to set the Z label.
4fill in blank
hard

Fill both blanks to create a 3D line plot with points (1,2,3) and (4,5,6).

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection=[1])
ax.plot([1, 4], [2, 5], [2])
plt.show()
Drag options to blanks, or click blank then click option'
A'3d'
B[3, 6]
C[3, 5]
D[4, 6]
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong projection strings like '3D'.
Using incorrect z coordinate lists.
5fill in blank
hard

Fill all three blanks to create a 3D surface plot of Z = X^2 + Y^2 over a grid.

Matplotlib
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()
Drag options to blanks, or click blank then click option'
A'3d'
B**
C^
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '^' which is bitwise XOR, not power.
Using '*' which is multiplication, not power.