Challenge - 5 Problems
3D Bar Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of 3D Bar Chart Data Arrays
What is the output of the following code snippet that prepares data for a 3D bar chart?
Matplotlib
import numpy as np x = np.arange(3) y = np.arange(2) xpos, ypos = np.meshgrid(x, y) xpos = xpos.flatten() ypos = ypos.flatten() zpos = np.zeros_like(xpos) print(xpos, ypos, zpos)
Attempts:
2 left
💡 Hint
Think about how meshgrid arranges coordinates and what flatten() does.
✗ Incorrect
np.meshgrid creates coordinate matrices from coordinate vectors. Flattening these matrices gives arrays of x and y positions for bars. zpos is zeros because bars start from zero height.
❓ data_output
intermediate1:00remaining
Number of Bars in 3D Bar Chart
Given x = range(4) and y = range(3), how many bars will be drawn in a 3D bar chart created by plotting all combinations of x and y?
Attempts:
2 left
💡 Hint
Multiply the number of x positions by the number of y positions.
✗ Incorrect
Each x value pairs with each y value, so total bars = 4 * 3 = 12.
❓ visualization
advanced3:00remaining
Identify the Correct 3D Bar Chart Plot
Which option shows the correct 3D bar chart plot code that creates bars with heights from the list [1, 3, 2, 5] at positions (0,0), (1,0), (0,1), and (1,1)?
Attempts:
2 left
💡 Hint
Check the order and length of parameters for bar3d: xpos, ypos, zpos, dx, dy, dz.
✗ Incorrect
bar3d requires arrays for x, y, z positions, widths dx, dy, and heights dz. Option B correctly provides all six parameters with matching lengths.
🔧 Debug
advanced3:00remaining
Error in 3D Bar Chart Plotting Code
What error will this code raise?
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = [0,1]
y = [0,1]
z = [0,0]
dx = dy = dz = [1,2]
ax.bar3d(x, y, z, dx, dy, dz)
plt.show()
Matplotlib
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = [0,1] y = [0,1] z = [0,0] dx = dy = dz = [1,2] ax.bar3d(x, y, z, dx, dy, dz) plt.show()
Attempts:
2 left
💡 Hint
Check how dx, dy, dz are assigned and their types.
✗ Incorrect
dx = dy = dz = [1,2] assigns the same list to all three variables. This causes bar3d to receive lists where it expects numbers or arrays of matching shape, leading to a ValueError.
🚀 Application
expert3:00remaining
Calculate Total Volume of Bars in 3D Bar Chart
Given the following data for a 3D bar chart:
x = [0, 1, 2]
y = [0, 1]
dz = [2, 3, 1, 4, 2, 5]
Each bar has width dx=1 and depth dy=1. What is the total volume of all bars combined?
Attempts:
2 left
💡 Hint
Volume of each bar = dx * dy * dz. Sum all volumes.
✗ Incorrect
Each bar volume is 1 * 1 * dz value. Sum dz values: 2+3+1+4+2+5 = 17. Since dx and dy are 1, total volume = 17.