0
0
Matplotlibdata~20 mins

3D plot limitations and alternatives in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
3D Plot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why are 3D plots often hard to interpret?

3D plots can look cool but sometimes they are not the best choice. Why might 3D plots be hard to understand?

ABecause 3D plots always use too many colors which confuse the viewer.
BBecause they can hide data points behind others and make it hard to see all details clearly.
CBecause 3D plots cannot show any numerical values on axes.
DBecause 3D plots do not allow any interaction or rotation.
Attempts:
2 left
💡 Hint

Think about how depth and overlapping points affect visibility.

Predict Output
intermediate
2:00remaining
Output of 3D scatter plot code snippet

What will the following code produce?

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([4, 5, 6])
z = np.array([7, 8, 9])

ax.scatter(x, y, z)
plt.show()
AA syntax error because Axes3D is not imported correctly.
BA 2D scatter plot ignoring the z values.
CA line plot connecting points in 3D space.
DA 3D scatter plot showing points at coordinates (1,4,7), (2,5,8), and (3,6,9).
Attempts:
2 left
💡 Hint

Check how the scatter method works with 3D axes.

data_output
advanced
1:30remaining
Data shape after flattening 3D array for 2D plotting

You have a 3D numpy array with shape (4, 3, 2). You flatten it to 2D for plotting. What will be the shape after flattening the first two dimensions?

Matplotlib
import numpy as np
arr = np.zeros((4, 3, 2))
flat_arr = arr.reshape(-1, 2)
print(flat_arr.shape)
A(12, 2)
B(4, 6)
C(6, 4)
D(2, 12)
Attempts:
2 left
💡 Hint

Multiply the first two dimensions to get the new first dimension.

visualization
advanced
1:30remaining
Choosing an alternative to 3D plots for better clarity

You want to show the relationship between three variables but 3D plots are confusing. Which alternative visualization can show three variables clearly in 2D?

AA pie chart showing proportions of one variable.
BA bar chart with one variable only.
CA scatter plot with color and size encoding the third variable.
DA simple line plot with only two variables.
Attempts:
2 left
💡 Hint

Think about how to show three variables in two dimensions.

🔧 Debug
expert
2:00remaining
Why does this 3D plot code fail to show points correctly?

Consider this code snippet:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111)

ax.scatter([1,2,3], [4,5,6], [7,8,9])
plt.show()

Why does it fail to plot points in 3D?

ABecause the subplot was not created with projection='3d', so it is a 2D plot.
BBecause scatter requires numpy arrays, not lists.
CBecause the figure was not shown with plt.draw() instead of plt.show().
DBecause matplotlib does not support 3D scatter plots.
Attempts:
2 left
💡 Hint

Check how the subplot is created for 3D plotting.