October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Overlay Two Bar Charts in Matplotlib with Python

Draw two Matplotlib bar series on the same category positions to overlay them, or offset the bars for a clearer side-by-side comparison.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

To overlay two bar charts in Matplotlib, draw both datasets on the same Axes at the same category positions. Use different colors and labels, then set partial transparency on the bars so the later series does not completely hide the earlier one.

Overlay two bar charts at the same positions

Each call to ax.bar() draws a bar series. Giving both calls the same category positions aligns their bars; the second call is drawn on top of the first. The example uses Matplotlib’s documented bar interface for positions, colors, labels, and transparency (bar API documentation).

import matplotlib.pyplot as plt

categories = ["A", "B", "C"]
values_one = [12, 18, 14]
values_two = [10, 21, 16]

fig, ax = plt.subplots()
ax.bar(categories, values_one, color="tab:blue", alpha=0.55, label="Series one")
ax.bar(categories, values_two, color="tab:orange", alpha=0.55, label="Series two")
ax.set_ylabel("Value")
ax.set_title("Overlaid bar charts")
ax.legend()
plt.show()

The alpha setting makes both series partly visible. Transparency is not a guarantee of easy reading: blended colors can be hard to distinguish, especially where bars overlap. If readers need to compare the individual values precisely, use grouped bars instead.

When a true overlay is useful

Use shared positions when the overlap itself is meaningful—for example, when you want to see whether two independent values occupy similar ranges for each category. Keep both datasets on a compatible scale, and use clearly different colors and legend labels. If one series should not visually dominate, adjust draw order or transparency; the series drawn last is in front.

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

Use grouped bars for side-by-side comparison

If “overlay” means compare two values for each category without one obscuring the other, offset the positions by half a bar width. The Matplotlib grouped-bar example uses this position-shifting approach (grouped bar chart with labels).

import numpy as np
import matplotlib.pyplot as plt

categories = ["A", "B", "C"]
values_one = [12, 18, 14]
values_two = [10, 21, 16]
x = np.arange(len(categories))
width = 0.38

fig, ax = plt.subplots()
ax.bar(x - width / 2, values_one, width, label="Series one")
ax.bar(x + width / 2, values_two, width, label="Series two")
ax.set_xticks(x, categories)
ax.legend()
plt.show()

This leaves each category at the center of a pair, with one series on either side. Explicit positions with ax.bar() work across a broad range of Matplotlib versions and allow precise control over spacing.

Using Matplotlib’s higher-level grouped API

The stable documentation for pyplot.grouped_bar is for Matplotlib 3.11.2. It describes the API as provisional and says it was added in Matplotlib 3.11, so check the installed version before using it. For code that must run on older installations or needs custom positioning, use the explicit bar approach above. See the grouped_bar API documentation.

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

Use stacked bars only for additive components

A stacked chart is different from an overlay: the second series starts at the height of the first, so the combined bar represents a total. In Matplotlib, pass the first series as bottom when drawing the next one. This is appropriate when values are components that should add together, not when they are independent measurements to compare. The official stacked bar chart example demonstrates this pattern. Matplotlib’s lines, bars and markers gallery also presents grouped and stacked charts as distinct designs.

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

Choose the chart layout that matches the data

  • Same-position overlay: use for independent values when seeing overlap is informative; account for the front series covering the rear one.
  • Grouped bars: use to compare values side by side without occlusion.
  • Stacked bars: use when the series are additive parts of a total.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.