Overlay Two Bar Charts in Matplotlib with Python

My sales manager friend asked for one chart: each month’s target and actual sales in the same spot, so a miss jumps out. To overlay two bar charts in Matplotlib, call ax.bar() twice with the same x positions and make the front series narrower:

ax.bar(months, target, width=0.8, color="#cfd8e3")   # back
ax.bar(months, actual, width=0.45, color="#1f6feb")  # front

Here’s what we’re building, a target-vs-actual chart where green bars hit the goal and red ones missed it:

Overlay two bar charts in Matplotlib: narrow green and red actual sales bars in front of wide gray target bars for January to June 2026
The finished overlay: gray target bars behind, colored actual bars in front, with dollar labels on top.

In this tutorial, I’ll show you how to overlay two bar charts in Matplotlib one step at a time, starting from a plain bar chart and ending with a reusable function.

Before You Start: the overlay bar chart sample data

You need Python with Matplotlib installed (pip install matplotlib). I ran every step with Python 3.12.5 and Matplotlib 3.11.2; bar_label() needs Matplotlib 3.4 or newer, and its {:.1f}-style fmt needs 3.7+.

Our running sample is six months of 2026 sales for a fictional store, Cedar Ridge Outfitters, in thousands of US dollars:

ColumnTypeNotes
monthslist of strJan to Jun 2026, the x-axis categories
targetlist of floatMonthly sales goal in $K
actuallist of floatWhat the store really sold in $K

Before plotting, I print the gap for each month so I know what the chart should show:

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
target = [120.00, 125.00, 130.00, 135.00, 140.00, 150.00]   # $K
actual = [126.40, 118.75, 134.20, 141.90, 132.60, 158.30]   # $K

print(f"{'Month':<6}{'Target':>9}{'Actual':>9}{'Gap':>9}{'Hit':>8}")
for m, t, a in zip(months, target, actual):
    print(f"{m:<6}{t:>9.2f}{a:>9.2f}{a - t:>+9.2f}{a / t:>8.1%}")
print(f"Total {sum(target):>9.2f}{sum(actual):>9.2f}")

Output:

Month    Target   Actual      Gap     Hit
Jan      120.00   126.40    +6.40  105.3%
Feb      125.00   118.75    -6.25   95.0%
Mar      130.00   134.20    +4.20  103.2%
Apr      135.00   141.90    +6.90  105.1%
May      140.00   132.60    -7.40   94.7%
Jun      150.00   158.30    +8.30  105.5%
Total    800.00   812.15
VS Code output of the Cedar Ridge sample sales data showing target, actual, gap and percent of target for each month
February and May come in under target; the other four months beat it.

So February (95.0%) and May (94.7%) are the two misses. If you plot data like this often, my guide to a Matplotlib bar chart with values covers labels in more depth.

Step 1: Draw the target bars

We start with the series that goes in the back. A light gray keeps it quiet so the front bars stand out later:

import matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
target = [120.00, 125.00, 130.00, 135.00, 140.00, 150.00]   # $K
actual = [126.40, 118.75, 134.20, 141.90, 132.60, 158.30]   # $K

fig, ax = plt.subplots(figsize=(9, 5))
ax.bar(months, target, color="#cfd8e3", label="Target")
ax.set_ylabel("Sales ($K)")
ax.set_title("Cedar Ridge Outfitters - monthly sales, 2026")
plt.show()
Matplotlib plot window with six light gray target bars for January to June 2026
Step 1: only the target bars, rising from $120K in January to $150K in June.

Checkpoint: you should see six gray bars, with June the tallest at 150. If the y-axis range looks off, see setting the y-axis range of a Matplotlib bar chart.

Step 2: Overlay the actual bars with transparency

Add a second ax.bar() call on the same months. Matplotlib draws it on top, and alpha=0.6 lets the gray show through:

ax.bar(months, actual, color="#1f6feb", alpha=0.6, label="Actual")
ax.legend()
Matplotlib overlay of two bar charts with the same width, blue actual bars at alpha 0.6 on top of gray target bars
Same width plus alpha: the overlap mixes into one blended color, and the short misses are hard to spot.

You can see the problem: with equal widths, a miss only shows as a thin gray strip above the blue bar.

Step 3: Make the front bars narrower

Here’s the trick that makes an overlay readable: give the back series the full width and the front series about half of it. Both share the same center, so no x offset math is needed:

ax.bar(months, target, width=0.8, color="#cfd8e3", label="Target")
ax.bar(months, actual, width=0.45, color="#1f6feb", label="Actual")
ax.legend()
Matplotlib overlay bar chart with narrow blue actual bars centered in front of wide gray target bars
Narrow front bars: each blue bar sits inside its gray target, so you compare heights at a glance.

Checkpoint: February’s and May’s blue bars now end clearly below the gray tops. If you want bars next to each other instead, that’s a grouped chart; see creating a multiple bar chart in Matplotlib.

Step 4: Add value labels and a legend to the overlay bar chart

Your readers want numbers, not just shapes. ax.bar_label() writes each actual value above its bar:

bars = ax.bar(months, actual, width=0.45, color="#1f6feb", label="Actual")
ax.bar_label(bars, fmt="${:.1f}K", padding=3, fontsize=9)
ax.set_ylim(0, 180)
ax.grid(axis="y", alpha=0.3)
ax.set_axisbelow(True)
ax.legend(loc="upper left")
Matplotlib overlay bar chart with dollar value labels above the blue actual bars, a light y grid and a legend
Labels like $126.4K sit above every actual bar, and the legend names both series.

set_axisbelow(True) keeps the grid behind your bars, and the y limit of 180 leaves room for June’s label.

Step 5: Color missed targets red in the overlay chart

Last, each front bar gets green or red depending on whether it reached its target, and the whole chart moves into plot_overlay() so you can reuse it:

import matplotlib.pyplot as plt
from matplotlib.patches import Patch


def plot_overlay(months, target, actual, title):
    colors = ["#2e7d32" if a >= t else "#c62828"
              for a, t in zip(actual, target)]
    fig, ax = plt.subplots(figsize=(9, 5))
    ax.bar(months, target, width=0.8, color="#cfd8e3")
    bars = ax.bar(months, actual, width=0.45, color=colors)
    ax.bar_label(bars, fmt="${:.1f}K", padding=3, fontsize=9)
    ax.set_ylim(0, max(target + actual) * 1.2)
    ax.grid(axis="y", alpha=0.3)
    ax.set_axisbelow(True)
    ax.set_ylabel("Sales ($K)")
    ax.set_title(title)
    ax.legend(handles=[Patch(color="#cfd8e3", label="Target"),
                       Patch(color="#2e7d32", label="Hit target"),
                       Patch(color="#c62828", label="Missed target")],
              loc="upper left")
    return fig, ax

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
target = [120.00, 125.00, 130.00, 135.00, 140.00, 150.00]   # $K
actual = [126.40, 118.75, 134.20, 141.90, 132.60, 158.30]   # $K

plot_overlay(months, target, actual, "Cedar Ridge Outfitters - Jan-Jun 2026")
plt.show()

Since your colors vary per bar, the legend needs Patch handles. This is the chart you saw at the top.

Checkpoint: February ($118.8K) and May ($132.6K) are red; the other four bars are green.

Test the overlay chart with new numbers

A reusable chart should survive new data. I fed it the second half of 2026 and saved a PNG for the report at the same time:

h2_months = ["Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
h2_target = [155.00, 150.00, 145.00, 160.00, 175.00, 210.00]
h2_actual = [149.80, 156.20, 147.90, 152.40, 181.30, 224.70]

fig, ax = plot_overlay(h2_months, h2_target, h2_actual,
                       "Cedar Ridge Outfitters - Jul-Dec 2026")
fig.savefig("sales-jul-dec-2026.png", dpi=150, bbox_inches="tight")
plt.show()