how-to · 5 min read
How to plot experimental data with error bars
Plotting experimental data is not decoration: the figure decides what a reader notices, so the chart type, the error bars and the axis labels all carry scientific claims. A scatter plot with labelled uncertainty is usually a fairer summary than a bar chart that hides the spread.
This walkthrough follows the experimental data plotter from pasted rows to exported figure: x,y rows with an optional error column, a scatter or line chart, axis labels, a least-squares fit with slope, intercept and r², and SVG, PNG or CSV output.
Start with tidy rows, not a formatted table
The plotter wants one measurement per row: x first, y second, and optionally the uncertainty on y as a third column. A header such as x, y, error is skipped if present, and the delimiter is detected from the first line, so a comma-separated export, a tab-separated copy from a spreadsheet and plain space-separated values all work. Keep both columns in the units of the measurement and convert before pasting if the units differ.
A short example makes the arithmetic visible. With the rows (1, 2.5), (2, 4.9) and (3, 7.2) the fitted line is y = 2.35x + 0.1667 and r² is about 0.9998, close to a straight line but not perfect. Those numbers come from the tool; your own data will give its own slope and intercept, and the point of the example is that the fit reports the relationship instead of hiding it.
Choose the chart type the data supports
Scatter is the default for independent measurements. Each point stands alone, the eye can see clusters, gaps and outliers, and nothing implies an ordering that the experiment did not have. Use line when the x values form a sequence such as time, wavelength or a temperature ramp, because connecting the points then expresses how the quantity changed between observations rather than inventing a category order.
Scatter + line shows both the individual points and the path through them, which is useful when the measurements are ordered but the spread still matters. Avoid connecting unrelated conditions such as different samples or treatments; a line through them suggests a trend that no single experiment measured. The plotter draws one series per chart, so put separate conditions in separate figures rather than in one misleading line.
Error bars need a definition, not just a size
Add the third column when each point has a known uncertainty, such as the standard deviation of repeated measurements, the standard error of the mean, a confidence interval half-width or an instrument tolerance. The plotter draws a symmetric y error bar of that size, so whatever you place in the column must match how the figure caption describes it; an unlabelled bar is not information.
If the data has no replicate or calibration uncertainty, leaving the third column out is more honest than inventing a plausible bar. Note that the error column affects only the drawing: the least-squares fit weights every point equally, so a fit that should be weighted by uncertainty needs a different calculation.
Add a least-squares fit only when a line is plausible
The fit answers one question: what straight line minimises the squared vertical distances to these points? It reports the slope, intercept and r², and those numbers are only meaningful when a straight-line relationship is a reasonable model over the plotted range. A curve, a cluster of categories or a single extreme value can all make the fit tidy and wrong.
Two points always produce a perfect line and an r² of 1, so a fit through two pairs is arithmetic rather than evidence. The intercept may also be meaningless if x never approaches zero. Read the points around the line, quote the equation with the range of x and the number of points, and treat a fitted line as a summary of the data rather than a law.
Label, export and check the figure before sharing
Give the chart a title that says what is plotted, and label both axes with the quantity and its unit. The plotter lets you edit all three labels and updates the drawing as you type. Export the vectors as SVG when the figure will be scaled or edited, a 2× PNG when it goes into slides or a document, and the CSV when someone needs the cleaned numeric rows; all three downloads are generated locally.
Before sharing, check that no label or error bar is clipped. Naming the files descriptively and writing a caption that states the error-bar definition, the number of measurements and the fitted range takes a minute and prevents most figure-reading mistakes.
- One row per measurement, with units converted before pasting.
- Scatter for independent points, line only for ordered sequences.
- A third column is an uncertainty: say which one in the caption.
- Only fit a line when a straight trend is plausible over the plotted range.
- Export SVG for print, PNG for slides, CSV for the data.