Skip to content

Instantly share code, notes, and snippets.

@jbelloncastro
Created September 30, 2019 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbelloncastro/5baae338dc2916a72e82f2072bd6531a to your computer and use it in GitHub Desktop.
Save jbelloncastro/5baae338dc2916a72e82f2072bd6531a to your computer and use it in GitHub Desktop.
Gnuplot chart for a histogram with error bars
#!/usr/bin/gnuplot
# Output format
set terminal png enhanced font "freesans,16" linewidth 2
# Caption
set key inside top horizontal nobox font ",12"
set xlabel ''
set ylabel ''
set auto x
set xtics rotate by -30 offset -1
set style data histogram
set style fill solid border -1
set style histogram errorbars gap 1 lw 1
set datafile separator ";"
set yrange [0.4:1.4]
set style line 1 lt 2
set style line 2 lt 3
set style line 3 lt 4
# Compute error of a/b
# 1. compute relative errors
# 2. add them together
# 3. convert the result back to absolute (multiply by a/b)
error(a,aerr,b,berr) = ((aerr/a) + (berr/b)) * (a/b)
set title 'Title'
set output 'output.png'
# Note: 'every ::3' starts counting from row 3 onwards, when there is more than
# one heading row
plot 'input.dat' every ::3 using ($2/$3):(error($2,$6,$3,$7)):xtic(1) ls 1 ti 'compute', \
'' every ::3 using ($5/$3):(error($5,$9,$2,$7)):xtic(1) ls 2 ti 'prefetch', \
'' every ::3 using ($4/$3):(error($4,$8,$2,$7)):xtic(1) ls 3 ti 'fetch'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment