Bird
0
0

You want to plot a 3D bar chart showing monthly revenue for 4 products over 3 quarters. Which data setup is correct for ax.bar3d()?

hard📝 Application Q8 of 15
Matplotlib - 3D Plotting
You want to plot a 3D bar chart showing monthly revenue for 4 products over 3 quarters. Which data setup is correct for ax.bar3d()?
Ax = [0,1,2,3]*3; y = [0]*4 + [1]*4 + [2]*4; z = [0]*12; dx = dy = 0.8; dz = revenue_values
Bx = [0,1,2]; y = [0,1,2,3]; z = [0]*7; dx = dy = 1; dz = revenue_values
Cx = [0,1,2,3]; y = [0,1,2]; z = [0]*7; dx = dy = 1; dz = revenue_values
Dx = [0,1,2,3]; y = [0,1,2]; z = [0]*12; dx = dy = 1; dz = revenue_values
Step-by-Step Solution
Solution:
  1. Step 1: Understand data dimensions

    4 products over 3 quarters = 12 bars total.
  2. Step 2: Setup x and y coordinates

    x repeats product indices for each quarter; y repeats quarter indices for each product.
  3. Step 3: Initialize z and bar sizes

    z is zero (base height), dx and dy set bar widths, dz holds revenue heights.
  4. Step 4: Evaluate options

    x = [0,1,2,3]*3; y = [0]*4 + [1]*4 + [2]*4; z = [0]*12; dx = dy = 0.8; dz = revenue_values correctly matches lengths and setup; others have mismatched lengths or incorrect repeats.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Coordinates must align with data length [OK]
Quick Trick: Match x, y lengths to data points count [OK]
Common Mistakes:
  • Mismatching lengths of coordinate arrays
  • Incorrect repetition of x or y values
  • Setting wrong bar widths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes