Error Bars in Gnuplot

Error bars need one extra data column: plot with the yerrorbars style and give three columns to using — x, y, and the error size. The script below plots five measurements with symmetric uncertainties.

The file errors.dat holds the sample number, the measured value, and its uncertainty (lines starting with # are comments and are ignored):

# sample  value  uncertainty
1  10.2  0.8
2  11.5  0.6
3  10.8  0.9
4  12.3  0.7
5  13.1  1.0
set title "Measurements with Uncertainty"
set xlabel "Sample"
set ylabel "Value"
set xrange [0:6]
set grid
plot "errors.dat" using 1:2:3 with yerrorbars pointtype 7 pointsize 1.2 title "Measured", \
     "errors.dat" using 1:2 with lines linewidth 2 title "Trend"

What each part does

The key is the three-column using 1:2:3: column 1 is x, column 2 is y, and column 3 is the y error delta. With with yerrorbars, gnuplot draws a marker at each (x, y) point plus a vertical bar from y−delta to y+delta with small caps at the ends. pointtype 7 and pointsize 1.2 style the markers. The second plot clause re-reads the same file with plain using 1:2 and with lines to connect the central values as a trend line — error bars and a line through the points are separate plot elements, combined with a comma.

If your file stores explicit lower and upper bounds instead of a delta, use four columns: using 1:2:3:4, where columns 3 and 4 are y-low and y-high. Horizontal uncertainty works symmetrically with xerrorbars (using 1:2:3 = x, y, x-delta), and xyerrorbars combines both directions with four or six columns.

Variants and going further

The yerrorlines style merges the two clauses above: it draws the connecting line and the error bars in one element, plot "errors.dat" using 1:2:3 with yerrorlines. For publication figures, set the error-bar cap width with set errorbars 2.0 (in character-width units) and consider removing the trend line — a fitted curve from a real fit belongs on measurement data more than a connect-the-dots line.

Common mistakes

  • Bars all zero-length or missing: the third using column points at the wrong column — count columns in the file, remembering that # comment lines are not data lines. Also confirm you did not swap in a two-column using 1:2 for the error-bar element.
  • “Wrong number of columns” or truncated plot: a four-column (low/high) file plotted with a three-column spec (or the reverse). Match the using list to the file layout: 3 columns for delta form, 4 for low/high form.

Related tutorials: Curve Fitting with fit, Plot CSV Data in Gnuplot. See also the full Gnuplot Tutorials index.

Try it online: Try both yerrorbars and yerrorlines on the sample data in the online terminal to see which reads better. Paste the script into the Gnuplot Online terminal and run it in your browser — no install needed. To run gnuplot locally instead, see the installation guide and the download page.

Go deeper: For a systematic walk through gnuplot from first plots to publication-ready figures, see Gnuplot in Action by Philipp K. Janert — Janert is a gnuplot developer, and the book is the most complete tutorial reference for the program. Affiliate link: see our Affiliate Disclosure.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *