Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Label Multiple Bars and Series in Matplotlib

Use ax.bar_label() on each returned BarContainer to label every series in a Matplotlib chart, with options for custom text, formatting, and stacked bars.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.