Search code examples
gnuplothistogram

gnuplot histogram errorbar problems


Summary

I'm trying to use error bars with gnuplot but am running into two problems. The first problem is that the error bars are not correctly aligned. The second problem is that I can't specify multiple data sets when using error bars.

First problem: error bar alignment

The first problem is that the error bars are not correctly aligned as can be seen in the following image:

enter image description here

This image was generated from the following script:

set terminal postscript eps enhanced 
set yrange [0:20]
set style data histogram
set style histogram errorbars gap 1
set output 'out.eps'
plot "test.dat" using 2:3

and the following test input data

header colA   errA     colB  errB
typeX   10.0   1.0      15.1   1.5
typeY   5.0   0.5      12.1   0.8

The bar error bar at point 0.5 on the x-axis should be associated with first histogram entry rather than being offset. I've tried a few different things, and this simple example is very close to what is shown in the gnuplot 5.0 user manual on page 55 (screenshot below since there isn't an HTML version.

enter image description here

Second problem: specifying multiple data sets with error bars

Using the same test input data from before, the following code will generate a histogram plot with two data sets without using error bars:

set terminal postscript eps enhanced 
set yrange [0:20]
set style data histogram
set style histogram 
set output 'out.eps'
plot 'test.dat' using 2, '' using 4

enter image description here

But if I try to modify this, as shown below, to generate error bars I get an invalid eps file that can't be displayed.

set terminal postscript eps enhanced     
set yrange [0:20]
set style data histogram
set style histogram errorbars
set output 'out2.eps'
plot 'test.dat' using 2:3, '' using 4:5

I have tested this on both OS X with gnuplot 5.0 patchlevel 2 and on Arch Linux with the same version of gnuplot and also with gnuplot 5.0 patchlevel 3


Solution

  • Comment out the first line (header), this solved both problems:

    #header colA   errA     colB  errB
    typeX   10.0   1.0      15.1   1.5
    typeY   5.0   0.5      12.1   0.8