0
0
Matplotlibdata~20 mins

3D bar charts in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
3D Bar Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[0 1 2 0 1 2] [0 0 0 1 1 1] [0 0 0 0 0 0]
B[0 0 1 1 2 2] [0 1 0 1 0 1] [0 0 0 0 0 0]
C[0 1 2] [0 1] [0 0 0]
D[0 1 2 0 1 2] [0 1 0 1 0 1] [0 0 0 0 0 0]
Attempts:
2 left
💡 Hint
Think about how meshgrid arranges coordinates and what flatten() does.
data_output
intermediate
1: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?
A7
B9
C6
D12
Attempts:
2 left
💡 Hint
Multiply the number of x positions by the number of y positions.
visualization
advanced
3: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)?
Aax.bar3d([0,1,0,1], [0,0,1,1], [0,0,0,0], 1, 1, [1,3,2,5])
Bax.bar3d([0,1,0,1], [0,0,1,1], [0,0,0,0], [1,1,1,1], [1,1,1,1], [1,3,2,5])
Cax.bar3d([0,1,0,1], [0,0,1,1], [1,3,2,5], 1, 1, 0)
Dax.bar3d([0,0,1,1], [0,1,0,1], [0,0,0,0], 1, 1, [1,3,2,5])
Attempts:
2 left
💡 Hint
Check the order and length of parameters for bar3d: xpos, ypos, zpos, dx, dy, dz.
🔧 Debug
advanced
3: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()
ATypeError: 'int' object is not iterable
BTypeError: bar3d() missing 3 required positional arguments
CValueError: setting an array element with a sequence
DNo error, plot displays correctly
Attempts:
2 left
💡 Hint
Check how dx, dy, dz are assigned and their types.
🚀 Application
expert
3: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?
A17
B18
C19
D20
Attempts:
2 left
💡 Hint
Volume of each bar = dx * dy * dz. Sum all volumes.