Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Plot Multiple Bar Charts with Time Series in Matplotlib

Compare aligned reporting periods with grouped bars, preserve irregular date spacing with date positions, or use shared-x panels when series need separate scales.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For several data series measured at the same reporting periods, plot grouped bars on one Matplotlib axes to compare values side by side. If dates are irregular and their actual spacing matters, use dates as x-coordinates instead of treating them as equally spaced categories. For separate scales or less crowding, put the series in stacked panels with a shared time axis.

Choose how the time axis should work

First decide whether the labels represent categories or actual elapsed time. Months such as January, February, and March are often treated as equally spaced reporting categories. A sequence of real timestamps may have uneven gaps; plotting those dates as x positions preserves that spacing. The choice affects both bar placement and what the chart communicates.

  • Comparable reporting periods: use grouped bars for side-by-side comparisons at each category.
  • Irregularly spaced observations: use date values as x positions and format the date ticks for readability.
  • Different scales or crowded data: use separate panels with a shared x-axis.

Plot grouped bars for aligned reporting periods

This example treats the periods as equally spaced categories and assumes both series contain one value for every period in the same order. Each series is offset by half the bar width so the bars sit beside one another.

import numpy as np
import matplotlib.pyplot as plt

periods = ["Jan", "Feb", "Mar", "Apr"]
series_a = [12, 15, 11, 18]
series_b = [10, 13, 14, 16]

x = np.arange(len(periods))
width = 0.38

fig, ax = plt.subplots(figsize=(8, 4.5), layout="constrained")
ax.bar(x - width / 2, series_a, width, label="Series A")
ax.bar(x + width / 2, series_b, width, label="Series B")
ax.set_xticks(x, periods)
ax.set_xlabel("Period")
ax.set_ylabel("Value")
ax.set_title("Values by period")
ax.legend()
plt.show()

The object-oriented pattern—create a figure and axes, then call plotting methods on the axes—keeps chart construction and formatting explicit. Matplotlib’s plotting interfaces guide describes this approach. The Axes.bar reference documents the bar positions, widths, labels, and other controls used here.

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.

Use Matplotlib’s grouped-bar convenience API only when available

Matplotlib also documents Axes.grouped_bar for categorical datasets sharing common categories. That API was added in Matplotlib 3.11 and is provisional, so code that must run across older or compatibility-sensitive installations should use explicit positions with bar, as above. Check the current bar API documentation and the installed Matplotlib version before choosing the convenience method.

Plot genuinely date-spaced observations

When the elapsed time between observations is meaningful, pass date values as the x positions rather than mapping each date to a consecutive integer. Then choose date tick locators and formatters appropriate to the range so labels remain legible. Matplotlib’s gallery includes date plotting and date tick locator/formatter examples.

For multiple series on the same date positions, keep the dates aligned and choose bar widths suitable for the date units. Do not use equal category spacing if it would hide irregular gaps. The bar reference provides control over positions, dimensions, and baseline.

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

Use shared-x panels when one grouped chart is not suitable

If each series needs its own scale or a grouped chart is too crowded, draw each series in a separate axes and share the x-axis. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import matplotlib.pyplot as plt

fig, axs = plt.subplots(2, 1, sharex=True, layout="constrained")
axs[0].bar(dates, series_a)
axs[0].set_ylabel("Series A")
axs[1].bar(dates, series_b)
axs[1].set_ylabel("Series B")
axs[1].set_xlabel("Date")

A shared x-axis keeps the time positions aligned; in a shared column, Matplotlib displays x tick labels on the bottom axes. See the subplots reference and the shared-axis example for subplot and shared-axis behavior.

Keep the chart interpretable

  • Make sure every series uses the same category order or aligned date positions.
  • Label each series in the legend, name the time axis, and include units on the value axis.
  • Prefer grouped bars when readers need to compare series within each period; choose panels when separate scales or reduced crowding matter more.
  • Format date ticks to suit the date range, especially when observations are irregularly spaced.

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.