St · Statistics & Probability

How to Add a Line to a Bar Chart

Updated 13 October 2026

At a glance

  1. 1. Choose the line’s meaning

    Decide whether the line is another data series, a target, or a gridline; each should be drawn differently.

  2. 2. Align categories

    Place each line value at the same category position as its corresponding bar.

  3. 3. Check the units

    Use a secondary axis only for a different unit, and label both axes clearly.

  4. 4. Review readability

    Check the legend, scales, colors, and whether the combined chart makes the comparison clear.

A line can add a second data series to a bar chart, show a target or threshold, or simply provide gridlines. The right approach depends on what the line represents. The key is to align data series to the same categories and make any different measurement scale obvious.

Choose what kind of line you need

If you want to show a second value for each category, plot a point for each category and connect those points. This is useful for showing how a measure changes across ordered categories, such as monthly sales alongside a monthly percentage. Use a secondary vertical axis if the two series have different units or very different scales.

If you want to show a target, average, or threshold, draw a horizontal reference line across the chart. It does not represent a value for each category, so it usually does not need a second axis. If you mean the faint horizontal or vertical guides behind the data, those are gridlines; turn them on through the chart’s grid or formatting options.

Before combining bars and a line, ask whether the measures are meaningfully compared on one chart. Bars and lines are easiest to interpret when categories have a natural order, such as time. For unordered groups, a connected line may wrongly suggest continuity between categories.

Align the line with the bars

The line’s points should sit at the centers of the corresponding bars, not between categories. For grouped bars, decide which bar group each line value belongs to, or position the line at the group center. Keep the category order identical for bars and line values.

When both series use the same unit and a comparable range, put them on the same vertical axis. When they use different units, a secondary axis can make both visible, but label each axis with its measure and unit. Do not imply that a bar height and a line height are directly comparable if they use different scales.

Worked example in Python

Suppose quarterly sales are measured in thousands of dollars, while conversion rate is a percentage. Sales use the bars and conversion rate uses the line. The following Matplotlib example puts the sales scale on the left and the percentage scale on the right:

import matplotlib.pyplot as plt
import numpy as np

quarters = ["Q1", "Q2", "Q3", "Q4"]
sales = [12, 16, 14, 20]          # thousands of dollars
conversion = [2.0, 2.5, 2.2, 3.0] # percent
x = np.arange(len(quarters))

fig, ax1 = plt.subplots()
bars = ax1.bar(x, sales, color="steelblue", label="Sales ($000)")
ax1.set_ylabel("Sales ($000)")
ax1.set_xticks(x)
ax1.set_xticklabels(quarters)
ax1.set_axisbelow(True)
ax1.grid(axis="y", color="0.85")

ax2 = ax1.twinx()
line, = ax2.plot(
    x, conversion, color="darkorange", marker="o",
    linewidth=2, label="Conversion (%)"
)
ax2.set_ylabel("Conversion (%)")
ax2.set_ylim(0, 4)

ax1.legend([bars, line], ["Sales ($000)", "Conversion (%)"])
ax1.set_title("Quarterly sales and conversion rate")
fig.tight_layout()
plt.show()

The two axes share the same horizontal positions, so the Q1 line point aligns with the Q1 bar, and so on. twinx() creates a second vertical axis for the percentage. Setting its range explicitly makes the scale visible and deliberate; the legend identifies which series uses each scale.

A secondary axis can change how steep the line appears. Its height should not be read as a direct comparison with the bars. If that comparison is central to your message, consider putting the series in separate, aligned charts or converting them to a common measure, such as an index with a clearly stated baseline.

Add a target or threshold line

For a horizontal target, use the same vertical axis as the bars when the target shares their units. In Matplotlib, for example, ax1.axhline(y=15, color="red", linestyle="--", label="Target") adds a dashed line at 15. Add the target to the legend, and make sure it is not hidden behind the bars. In spreadsheet software, look for a chart option to add a constant-value series or a reference line; the exact menu names vary by program.

Common mistakes

  • Using a line for unordered categories: Connecting values for unrelated groups can imply a trend that does not exist. Use points without connecting segments, or keep the series in a separate chart.
  • Forgetting the secondary-axis label: Readers need to know what the line measures and which scale applies to it. Label the unit, not just “right axis.”
  • Choosing axis limits to exaggerate a pattern: The secondary scale controls the line’s apparent rise and fall. Choose limits deliberately and disclose them through tick marks and labels.
  • Using too many series: Several bar groups and multiple lines can make a chart difficult to decode. Reduce the number of series or split the display into small charts.
  • Relying on color alone: Use distinct markers or line styles as well as color, and include a readable legend so the chart remains understandable when printed in grayscale.

References

  1. Matplotlib documentation: Axes.twinx
  2. Matplotlib documentation: Axes.bar

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.