Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsTo add numeric labels to multiple bars in Matplotlib, call ax.bar_label() on each BarContainer returned by ax.bar(). For a grouped chart, retain the container from every bar call and label each one separately. Use custom labels when the text should differ from the bar values, and choose edge or center placement to control what stacked bars display.
Label each bar series separately
Each call to ax.bar() returns a BarContainer. Pass that container to ax.bar_label() to annotate its bars. For multiple series, keep each returned container rather than trying to label the whole axes at once.
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
categories = ["A", "B", "C"]
series_a = [4, 7, 5]
series_b = [6, 3, 8]
x = range(len(categories))
width = 0.38
fig, ax = plt.subplots()
bars_a = ax.bar([i - width / 2 for i in x], series_a, width, label="Series A")
bars_b = ax.bar([i + width / 2 for i in x], series_b, width, label="Series B")
ax.bar_label(bars_a, fmt="{:g}", padding=3)
ax.bar_label(bars_b, fmt="{:g}", padding=3)
ax.set_xticks(list(x), categories)
ax.legend()
fig.tight_layout()
The two calls to bar_label add values to their respective series. The category names are set on the x-axis, while label in each bar call supplies the series name for the legend. These are three distinct kinds of labels: values on bars, category tick labels, and legend labels. See Matplotlib’s bar API for category handling and its bar chart examples for grouped-chart patterns.
Recommended Free Tools
Use custom text instead of numeric values
Pass a sequence to labels when each bar needs specific text. The sequence corresponds to the bars in that container:
#1 Best Overall
bars = ax.bar(categories, values)
ax.bar_label(bars, labels=["four", "seven", "five"])
Use fmt to format numeric values instead. The default format is %g; format strings and callable formatters are also supported in versions that provide them. The bar_label API documentation notes that callable formatters and brace-style formatting were added in Matplotlib 3.7.
Choose what stacked-bar labels mean
For stacked bars, label each component’s container. The default label_type="edge" positions the label at the segment endpoint and reports that endpoint value. Set label_type="center" to put a label in the middle of each segment and show the segment’s length instead. Choose center for component sizes and edge for cumulative endpoint values.
Set category labels and legend labels independently
For an ordinary grouped chart, the x positions determine where bars appear, ax.set_xticks(..., categories) supplies category names, and each bar call’s label argument supplies a legend entry. Matplotlib’s grouped_bar API offers a higher-level option for shared categories, with tick_labels for categories and dataset labels for the legend. It was introduced in Matplotlib 3.11 and is marked provisional in that API, so explicit bar calls remain useful when you need individual position or bar control.
Prevent labels from being clipped
Labels placed at bar edges can extend beyond the axes, especially with positive values near the upper limit. Inspect the rendered figure and adjust the axis limits or layout if text is cut off. Matplotlib explicitly cautions that “You may need to adjust the axis limits to fit the labels” in its bar_label documentation. In the example, fig.tight_layout() helps with figure spacing, but it does not replace changing axis limits when labels exceed the plotted range.
Rank #3
Check version-sensitive options
The cited current stable documentation is for Matplotlib 3.11.2. According to the Matplotlib 3.11.0 release notes, that release was dated June 11, 2026, and introduced grouped_bar. The bar_label documentation says callable and brace-style formatters arrived in 3.7, while per-label array padding was added in 3.11. If your code uses those newer options, check the installed version; the cited API pages do not provide a complete compatibility table for every release.
Quick Recap
Best 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.




