Skip to main content

Error Bars

What are error bars?​

Error bars are short lines drawn through a point or bar on a chart to show how uncertain, or how variable, that value is. Each runs from a low to a high value around the plotted value, usually a mean. They can show the standard deviation, the standard error or a confidence interval, so the chart must say which.

A chart of plant height in four fertiliser groups (Control, Low, Medium and High dose), 10 plants each: faint dots show every plant, and beside them three error bars around each group's mean show the standard deviation (widest), the standard error (narrowest) and the 95% confidence interval

The same four groups of plants with three kinds of error bar side by side: standard deviation, standard error and 95% confidence interval (sample data). Try the interactive version.

Key takeaways
  • An error bar shows the uncertainty or spread around a plotted value, usually a mean.
  • The three common kinds look identical but mean different things: standard deviation (SD) shows the spread of the data; standard error (SE) and confidence intervals (CI) show how precisely the mean is known.
  • A chart with error bars must say which kind they are, and the sample size (n). Without that, they can't be read.
  • Overlap is not a test. Standard error bars that don't overlap can still mean "no significant difference", and 95% confidence intervals that overlap a little can still mean "significant".

How to read error bars​

Left: the parts of one error bar, with a marker at the mean (12.03 cm), an upper and a lower arm of 1.14 cm each, and a cap at each end (13.17 and 10.89 cm), labelled as a 95% confidence interval for 10 plants. Right: two groups' 95% confidence intervals, Low dose and Medium dose, overlapping by 0.31 cm, about a third of an arm, although a t-test gives P = 0.015

  1. Find out what the bars show. Look in the caption, legend or methods for "SD", "SE" (or "SEM", the standard error of the mean), "95% CI" or "range". This changes what the bar means more than anything else on the chart.
  2. Find the sample size, n. It's the number of independent measurements behind each value, for example 10 plants or 1,000 survey respondents. You need it to judge SE and CI bars.
  3. Read the marker. The point, or the top of the column, is the plotted value: usually the mean of the group.
  4. Read the length of each arm. Each arm runs from the mean to a cap. For SD or SE bars, one arm is one SD or one SE. For a confidence interval, the whole bar from cap to cap is the interval.
  5. Compare groups with care. Longer bars mean more spread or less precision. Whether two groups really differ depends on the kind of bar, the gap or overlap between them and n: see What does it mean when error bars overlap? below.

Bars don't have to be symmetrical. A confidence interval for a percentage near 0% or 100%, or for data drawn on a log scale, can have one arm longer than the other.

Standard deviation vs standard error vs confidence interval error bars​

Error bars come in two families. Descriptive bars (SD and range) describe the data: how spread out the individual measurements are. Inferential bars (SE and CI) describe the estimate: how precisely the mean, or another statistic, has been measured, and so what you can conclude from it.

Error barWhat it showsHow it's worked outAs n growsUse it to
Standard deviation (SD)The typical distance of individual measurements from the mean. For roughly bell-shaped data, about two-thirds of values fall within ±1 SD√( Σ(x − mean)² ÷ (n − 1) )Stays about the sameShow how variable the data is
Standard error (SE or SEM)How precisely the mean has been measured: the typical error of a mean from a sample this sizeSD ÷ √nShrinks: 4 times the data halves itCompare means, with the overlap rules below
95% confidence interval (CI)A range that, across many repeats of the study, would contain the true mean 95% of the timemean ± t × SE (t = 2.262 for n = 10; about 2 for n of 10 or more)Shrinks, like SEShow what you can conclude about the mean. Usually the best choice for comparisons
RangeThe lowest and highest valuesmin to maxTends to growShow the extremes. Rare; a box plot does it better

In the chart at the top of the page, the three bars around each mean come from the same 10 plants. The SD bars (orange) are the widest; the SE bars (blue) are about a third as long, because √10 ≈ 3.2; the 95% CI bars (pink) are 2.262 times the SE bars.

So the same data can look very precise or very noisy, depending on which bar you draw.

How to calculate error bars: a worked example​

Here are the steps for the Control group in the chart at the top: the heights of 10 plants, in cm.

11.1, 11.9, 13.9, 11.4, 9.2, 10.2, 14.1, 13.3, 12.2, 13.0

StepCalculationResult
1. Mean120.3 ÷ 1012.03 cm
2. Sum of squared differences from the mean(11.1 − 12.03)² + (11.9 − 12.03)² + …23.00
3. Standard deviation (SD)√(23.00 ÷ 9)1.60 cm
4. Standard error (SE)1.60 ÷ √100.51 cm
5. t value for a 95% CItwo-sided, n − 1 = 9 degrees of freedom2.262
6. Half-width of the 95% CI2.262 × 0.511.14 cm
7. Draw the barsSD: 12.03 ± 1.60 · SE: 12.03 ± 0.51 · 95% CI: 10.89 to 13.17

Notes:

  • Divide by n − 1, not n, when the data is a sample from a larger population, as it almost always is.
  • 6 of the 10 plants lie within ±1 SD of the mean (10.43 to 13.63 cm), close to the two-thirds you'd expect.
  • With large samples the t value approaches 1.96, so a 95% CI is often quoted as "mean ± 1.96 SE". With only 3 measurements it's 4.30, so the CI is more than four times the SE.

How to describe error bars​

Use this template in a caption or report:

Points show the mean [measure] of [n] [units] per group; error bars show [±1 SD / ±1 SE / the 95% confidence interval].

Worked example: "Points show the mean height of 10 plants per group after four weeks; error bars show the 95% confidence interval. Plants given the medium dose were 1.6 cm taller on average than those given the low dose (two-sample t-test, P = 0.015)."

What does it mean when error bars overlap?​

Overlap is only a rough guide, and what it means depends on the kind of bar. The rules of thumb below (from Cumming, Fidler and Vaux, 2007) hold for two independent groups with about 10 or more measurements each and arms of similar length. P is the P value of a test for a difference between the two means.

Bars shownWhat you see between the two barsRoughly means
SE barsThey overlapNot significant: P > 0.05
SE barsA gap about one arm wideP ≈ 0.05
SE barsA gap about two arms wideP ≈ 0.01
95% CIThey overlap by about half an armP ≈ 0.05
95% CITheir ends just touchP ≈ 0.01
95% CIA clear gapP < 0.01
SD barsAnythingNothing about significance: SD shows spread, not precision

To judge "half an arm", use the average length of the two arms that face each other.

The data in the chart at the top shows both traps:

  • Control vs Low dose: the SE bars don't overlap, but the difference isn't significant. The gap between them (0.34 cm) is less than one SE arm (about 0.45 cm), and a two-sample t-test gives P = 0.068.
  • Low vs Medium dose: the 95% CIs overlap, but the difference is significant. They overlap by 0.31 cm, about a third of an average arm (0.97 cm), and the t-test gives P = 0.015. The right half of the diagram above shows this pair.
  • Medium vs High dose: every kind of bar overlaps heavily, and P = 0.79. There's no sign of a difference.

Three cases where the rules don't apply:

  • Small samples. With n = 3 the rules change: SE bars need a gap of about two arms for P ≈ 0.05, and 95% CIs can overlap by a whole arm at P ≈ 0.05.
  • Repeated measurements on the same subjects, such as the same patients before and after a treatment. The bars show variation between subjects, not the change within each one, so their overlap says nothing about the change.
  • Many comparisons at once. Rules of thumb for one pair don't allow for the extra chance of a false positive when you compare many pairs.

For a firm answer, run the right statistical test on the data. Use the bars to see the size and precision of the effect.

When to use error bars​

Use error bars when each point on a chart is an estimate or a summary (usually a mean) and readers need to see how much to trust it, or how much the underlying data varies. Typical uses:

  • experiments: treatment and control groups, or the same measurement under several conditions;
  • surveys and polls: an estimate with its margin of error, which is half the width of a 95% confidence interval;
  • measurements and calibration: instrument readings with their measurement uncertainty, sometimes with horizontal error bars too when x is also measured;
  • model and benchmark results: the spread of scores across repeated runs.
ChartBest for
Error bars on points, lines or columnsA few summary values with their uncertainty, compared across groups or over time
Box plotThe shape of each group's data: median, quartiles, range and outliers
Scatter plot of the raw values (a dot plot)Small samples, where every value can be shown; often drawn with error bars on top, as in the chart at the top of this page
Line chart with a shaded bandMany points along a continuous x-axis, where a band (a confidence or uncertainty band) is easier to read than a bar at every point

Common error bar mistakes​

  • Not saying what the bars are. SD, SE and CI bars look identical. Always name the kind of bar and n in the caption or legend.
  • Choosing SE because it looks tidier. SE bars are shorter than SD bars by a factor of √n, so they make data look less variable. Pick the bar that answers your question: SD for spread, CI (or SE) for comparing means.
  • Counting replicates as n. Measuring the same sample three times isn't three independent results. n is the number of independent subjects or experiments; error bars from repeated measurements of one sample show only measurement noise.
  • Error bars with tiny samples. With n = 3, bars are themselves very uncertain. Show the individual values instead, or as well.
  • Bars on a column chart that hide the data. A column with an error bar shows only two numbers per group. Adding the individual points, as in the chart at the top, shows how the data is really spread.

How to create error bars in JavaScript, React or Angular​

SciChart.js has a dedicated error bars series, which draws vertical or horizontal error bars over any scatter, line or column series. Because SciChart.js draws with WebGL and WebGPU, charts stay smooth to zoom and pan with many points and live data. Try the chart below: scroll to zoom, drag to pan, double-click to reset, hover over a group to see its mean, SD, SE and 95% CI, and use the legend to show or hide each kind of bar.

Here is the code for this chart:

// Create a JavaScript chart with error bars in SciChart.js: the mean of each group with SD, SE and 95% CI bars
const {
SciChartSurface,
NumericAxis,
FastErrorBarsRenderableSeries,
XyScatterRenderableSeries,
HlcDataSeries,
XyDataSeries,
EllipsePointMarker,
TextLabelProvider,
EErrorMode,
EDataPointWidthMode,
EAxisAlignment,
NumberRange,
SciChartJsNavyTheme,
LegendModifier,
CursorModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"

const { wasmContext, sciChartSurface } = await SciChartSurface.create(divElementId, {
theme: new SciChartJsNavyTheme()
});

// Your data: one list of measurements per group
const { groups, heights } = getPlantHeights();

// 1. Work out the mean, standard deviation (SD), standard error (SE) and 95% confidence interval (CI) of each group
const T_95 = 2.262; // two-sided 95% t value for n - 1 = 9 degrees of freedom (10 plants per group)
const stats = heights.map((values) => {
const n = values.length;
const mean = values.reduce((sum, v) => sum + v, 0) / n;
const sd = Math.sqrt(values.reduce((sum, v) => sum + (v - mean) ** 2, 0) / (n - 1));
const se = sd / Math.sqrt(n);
return { n, mean, sd, se, ci: T_95 * se };
});
const means = stats.map((s) => s.mean);

// X axis: one group name at x = 0, 1, 2, 3
sciChartSurface.xAxes.add(
new NumericAxis(wasmContext, {
labelProvider: new TextLabelProvider({ labels: groups }),
autoTicks: false,
majorDelta: 1,
minorDelta: 1,
drawMajorGridLines: false,
drawMinorGridLines: false,
drawMajorBands: false,
growBy: new NumberRange(0.12, 0.07) // extra space on the left keeps the first group clear of the chart's bottom corner
})
);
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
axisAlignment: EAxisAlignment.Left,
axisTitle: "Plant height (cm)",
labelPrecision: 0,
growBy: new NumberRange(0.2, 0.06) // extra space at the bottom keeps the lowest dot clear of the chart's bottom corner
})
);

// 2. The raw data: every plant as a faint dot, spread a little sideways so dots with similar values don't hide each other
const random = seededRandom(7);
const dotX = [];
const dotY = [];
heights.forEach((values, group) => {
values.forEach((value) => {
dotX.push(group - 0.3 + (random() - 0.5) * 0.12);
dotY.push(value);
});
});
sciChartSurface.renderableSeries.add(
new XyScatterRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues: dotX, yValues: dotY, dataSeriesName: "Each plant" }),
pointMarker: new EllipsePointMarker(wasmContext, {
width: 8,
height: 8,
strokeThickness: 0,
fill: "#FFFFFF88"
})
})
);

// 3. Three error bar series around the same means, side by side: SD, SE and 95% CI
const errorBarTypes = [
{ name: "Mean ± SD", halfWidth: (s) => s.sd, offset: -0.1, color: "#F48420" },
{ name: "Mean ± SE", halfWidth: (s) => s.se, offset: 0.1, color: "#50C7E0" },
{ name: "Mean ± 95% CI", halfWidth: (s) => s.ci, offset: 0.3, color: "#E8336D" }
];
errorBarTypes.forEach((type) => {
sciChartSurface.renderableSeries.add(
new FastErrorBarsRenderableSeries(wasmContext, {
// HlcDataSeries: x, the value the bar is drawn around (y), and the top (high) and bottom (low) of each bar
dataSeries: new HlcDataSeries(wasmContext, {
xValues: stats.map((_, group) => group + type.offset),
yValues: means,
highValues: stats.map((s) => s.mean + type.halfWidth(s)),
lowValues: stats.map((s) => s.mean - type.halfWidth(s)),
dataSeriesName: type.name
}),
stroke: type.color,
strokeThickness: 3,
errorMode: EErrorMode.Both, // draw both arms, up and down
dataPointWidth: 0.12, // the width of the caps, in x-axis units
dataPointWidthMode: EDataPointWidthMode.Range,
// A marker at the mean of each group
pointMarker: new EllipsePointMarker(wasmContext, {
width: 12,
height: 12,
strokeThickness: 2,
stroke: "#FFFFFF",
fill: type.color
})
})
);
});

// Legend: tick a box to show or hide each kind of error bar
sciChartSurface.chartModifiers.add(new LegendModifier({ showCheckboxes: true }));

// Tooltip: the numbers behind each group's bars
sciChartSurface.chartModifiers.add(
new CursorModifier({
showTooltip: true,
tooltipDataTemplate: (seriesInfos) => {
if (seriesInfos.length === 0) return [];
const group = Math.round(seriesInfos[0].xValue);
const s = stats[group];
if (!s) return [];
const low = (s.mean - s.ci).toFixed(2);
const high = (s.mean + s.ci).toFixed(2);
return [
`${groups[group]} (n = ${s.n})`,
`Mean: ${s.mean.toFixed(2)} cm`,
`SD: ± ${s.sd.toFixed(2)}`,
`SE: ± ${s.se.toFixed(2)}`,
`95% CI: ${low} to ${high}`
];
}
})
);

// Zoom with the mouse wheel, pan by dragging and double-click to reset
sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier(), new ZoomPanModifier(), new ZoomExtentsModifier());

Key points:

  • Work out the means and the size of each bar (SD, SE or CI) before you chart them. The series draws the values it's given, so the statistics are your code's job.
  • An HlcDataSeries holds four values per point: xValues, yValues (the mean), and highValues and lowValues (the two ends of the bar, as absolute values, not distances from the mean). Different high and low distances give asymmetric bars.
  • A FastErrorBarsRenderableSeries draws the bars. errorMode draws both arms or only the upper or lower one; errorDirection: EErrorDirection.Horizontal draws horizontal bars for uncertainty in x; dataPointWidth sets the width of the caps; a pointMarker marks the mean.
  • Several series can share one HlcDataSeries, so the same data can drive a line or scatter series and its error bars. Here an XyScatterRenderableSeries draws each plant, and a LegendModifier with showCheckboxes lets readers toggle each kind of bar.

See it in the demo app: JavaScript error bar chart · React error bar chart · Angular error bar chart

Go deeper: SciChart.js error bar chart documentation, including horizontal error bars, one-sided bars and dashed styles.

Frequently asked questions​

What do error bars represent on a graph?​

Error bars show the uncertainty or variability around a plotted value, usually a mean. Depending on how they were calculated, they show how spread out the data is (standard deviation or range), or how precisely the mean has been measured (standard error or a confidence interval). The two kinds look the same, so a chart with error bars must say which one it uses and how many measurements each value is based on.

Are error bars standard deviation or standard error?​

They can be either, or a confidence interval, and there is no default. Standard deviation bars show how much individual measurements vary. Standard error bars show how precisely the mean is known, and they are smaller than standard deviation bars by a factor of the square root of the sample size. Check the caption or legend: if it doesn't say, you can't interpret the bars.

What does it mean when error bars overlap?​

It depends on the type of bar. For two independent groups of about 10 or more measurements each: overlapping standard error bars mean the difference is not statistically significant (P greater than 0.05). But 95% confidence intervals can overlap by up to about half of one arm and the difference can still be significant at P about 0.05. Overlap of standard deviation bars tells you nothing about significance. For a firm answer, run a statistical test.

What are 95% error bars?​

95% error bars show a 95% confidence interval: a range worked out from the data that, across many repeats of the same study, would contain the true value 95% of the time. For a mean, the interval is the mean plus or minus a t value times the standard error. With 10 or more measurements it is roughly the mean plus or minus 2 standard errors. A survey's margin of error is half the width of a 95% confidence interval.

How are error bars calculated?​

First work out the mean of each group. For standard deviation bars, take the square root of the sum of the squared differences from the mean, divided by n minus 1. For standard error bars, divide the standard deviation by the square root of n. For 95% confidence interval bars, multiply the standard error by the t value for n minus 1 degrees of freedom (2.262 for 10 measurements). Draw each bar from the mean minus that amount to the mean plus it.

How do I add error bars to a chart in JavaScript?​

With SciChart.js, put each point's x value, its plotted value and the top and bottom of its error bar into an HlcDataSeries (x, y, high and low values), then draw it with a FastErrorBarsRenderableSeries. Add a point marker to show the mean, or draw a scatter, line or column series under the bars. The same chart works in React with scichart-react and in Angular with scichart-angular.

Sources​