Challenge - 5 Problems
3D Scatter Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of 3D scatter plot with color mapping
What will be the color of the point at coordinates (2, 3, 4) in the 3D scatter plot generated by the code below?
Matplotlib
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = [1, 2, 3] y = [2, 3, 4] z = [3, 4, 5] colors = ['red', 'green', 'blue'] scatter = ax.scatter(x, y, z, c=colors) plt.show()
Attempts:
2 left
💡 Hint
Colors are assigned in order to the points based on the list provided.
✗ Incorrect
The second point has coordinates (2, 3, 4) and the color list assigns 'green' to the second point.
❓ data_output
intermediate1:30remaining
Number of points plotted in 3D scatter plot
How many points will be plotted by the following 3D scatter plot code?
Matplotlib
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = np.linspace(0, 1, 10) y = np.linspace(0, 1, 10) z = np.linspace(0, 1, 10) ax.scatter(x, y, z) plt.show()
Attempts:
2 left
💡 Hint
The scatter plot plots points for each index in the arrays.
✗ Incorrect
Each array has 10 points, and scatter plots points pairwise by index, so 10 points are plotted.
❓ visualization
advanced2:00remaining
Effect of marker size on 3D scatter plot
Which option shows the correct effect of changing marker size in a 3D scatter plot?
Matplotlib
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = np.array([1, 2, 3]) y = np.array([2, 3, 4]) z = np.array([3, 4, 5]) ax.scatter(x, y, z, s=100) plt.show()
Attempts:
2 left
💡 Hint
The 's' parameter controls marker size in scatter plots.
✗ Incorrect
Setting s=100 increases marker size making points larger than default.
🔧 Debug
advanced2:00remaining
Identify the error in 3D scatter plot code
What error will the following code produce when run?
Matplotlib
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111) x = [1, 2, 3] y = [4, 5, 6] z = [7, 8, 9] ax.scatter(x, y, z) plt.show()
Attempts:
2 left
💡 Hint
Check if the subplot is created with 3D projection.
✗ Incorrect
The subplot is created without 3D projection, so scatter expects only x and y, but z is given causing TypeError.
🚀 Application
expert3:00remaining
Interpreting clustering from 3D scatter plot data
Given the 3D scatter plot data below, which cluster center is closest to the point (5, 5, 5)?
Matplotlib
import numpy as np points = np.array([[1, 2, 3], [5, 5, 5], [9, 8, 7]]) cluster_centers = np.array([[0, 0, 0], [5, 5, 6], [10, 10, 10]]) # Calculate distances from point (5,5,5) to each cluster center point = np.array([5, 5, 5]) distances = np.linalg.norm(cluster_centers - point, axis=1) closest_index = np.argmin(distances) closest_center = cluster_centers[closest_index] closest_center
Attempts:
2 left
💡 Hint
Distance is shortest between points closest in all three dimensions.
✗ Incorrect
The cluster center [5, 5, 6] is closest to point [5, 5, 5] with distance 1, less than others.