When each category contains sub-groups (e.g. Q1-Q4 revenue broken down into Product A vs Product B), grouped and stacked bar charts provide multi-dimensional comparisons.
Grouped: Standing two athletes shoulder-to-shoulder. Stacked: Standing one athlete on top of the other's shoulders.
Setting `bottom=product_a` offsets the base of product B's bars by product A's height.
plt.bar(cats, b_vals, bottom=a_vals)Grouped bars require computing offset numerical coordinates `x - width/2` and `x + width/2` using `np.arange()`.
x = np.arange(len(cats))
plt.bar(x - 0.2, y1, width=0.4)
plt.bar(x + 0.2, y2, width=0.4)Avoid the top errors and bad plotting practices that trip up new Python developers
Switch from abstract numbers to relatable Cricket, Cinema & Business charts
Write Matplotlib code to solve the objective and see your live plot render
Create a stacked bar chart for `cats=['A', 'B']` with `base=[10, 20]` (color='#6366F1') and `top=[5, 15]` (color='#00D9C0') using `bottom=base`.
✓ bottom✓ plt.barTest your understanding to unlock the lesson completion badge