Free tools Windows power users keep installed
One-click scans. No signup required.
Use Axes.bar() once for each data series, setting bottom to the running total of the preceding series. That cumulative baseline stacks each new segment above the earlier ones. The Matplotlib 3.11.1 gallery demonstrates this approach in its official stacked bar chart example.
Build a stacked bar chart with a running bottom
Each series needs one value per category, in the same order as the category labels. Start with a zero-valued baseline, draw each series, then add its values to the baseline. The next series will begin at the cumulative height for each category.
import matplotlib.pyplot as plt
import numpy as np
labels = ["Group A", "Group B", "Group C"]
series = {
"First": np.array([4, 3, 5]),
"Second": np.array([2, 4, 1]),
"Third": np.array([3, 2, 2]),
}
fig, ax = plt.subplots()
bottom = np.zeros(len(labels))
for name, values in series.items():
ax.bar(labels, values, bottom=bottom, label=name)
bottom += values
ax.set_ylabel("Value")
ax.set_title("Values by group")
ax.legend()
plt.show()
-
labelssupplies the categories along the horizontal axis. Each array inseriesmust have one value per label, with values in matching order. -
bottombegins at zero for every category, so the first call draws the first series from the baseline.Recommended Free Tools
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
For each later call,
bottom=bottomstarts that series at the accumulated height. Update the array only after drawing the current series; otherwise that series would start above itself. -
Each
labelnames a component in the legend. The axis label and title describe what the values and categories represent.
This is the same cumulative-baseline pattern shown in the Matplotlib 3.11.1 gallery, which describes creating a stacked bar chart using bar.
Check the data and read the chart carefully
-
Keep category labels and component arrays aligned in both length and order; mismatches can associate values with the wrong category or prevent the calls from working as intended.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
The running total is maintained separately for every category. With three categories, for example,
bottomhas three entries—not one overall total. -
Only the bottom segment shares a common zero baseline. The height of a higher segment shows its value, but its starting position varies with the preceding components, so comparing those segments by visual position alone is harder.
Quick Recap
SaleBestseller No. 1Bestseller No. 2Bestseller No. 3Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




