Wednesday, January 30, 2008

error bars in gnuplot

I use gnuplot to make all my graphs for my thesis.

Some days ago I decided that it was about time I put some errorbars on the experimental values in my graphs (this is something that is pretty important in physics, and should be in all subjects that handle measured data) so I calculated my standard deviation from some fits I made and used them as my errors.

Now to plot them. Hmmm .. how do I do that?

Well, if you have a datafile called "data" and in it you have 3 columns, the first column representing the x-axis, the second column the data (the y-axis) and the 3 column the +/- error values on the data values in the second column then you just give the command

plot "data" using 1:2:3 with yerrorbars

and you get the data values with the errorbars set correctly.

Except it didn't really plot well for me. The lines that made up the errorbars were dashed in stead of solid when I printed them out into a eps file and if I wanted to have different colors, if they were all red like the default is then there was no problem, but having one data set green and another blue and a function that was supposed to be compared to the data as red, then I had problems.

I wondered a lot about that, tried several other plotting utilities (gees those graphical utilities are bad ... not intuitive at all I think) and went no where. I asked the nice people on the news group and there I was just told to either use the candlesticks mode or define the color by using the linetype option.

So I tried and tried with no luck.

Until finally I came across one sentence there that said in plain text to my question about why the error bars were dashed

That would be because your terminal setting has patterned linetypes (no "solid" option to the postscript driver)

and then it continued on to answer some more questions so this part did not register with me by some reason the first time I read this.

It seems that the default of gnuplot is to set the dash option with the postscript driver when you issue

set terminal postscript eps

So to get a solid line with your error bars in your eps files you have to issue

set terminal postscript eps solid

Took me quite a time to figure this little thing out but should have taken me a lot less time if I had read better what was written to me in that post :-)

Lesson of the day, read what is written for you :-)


Anonymous said...

I was trying to get non-dashed errorbars with linewidths and such following (otherwise a nice gnuplot help page) but nothing worked. So thanks a whole lot for this hint, made my day!

Anonymous said...

good tip! i found it useful too!
thanks :)

Anonymous said...

Ólafur, thanks for the hint. It helped here as well. Sometimes it's really annoying when when you're trying to get a simple task dome and some annoyances here and there just don't let you until you go through the manual :)

peter said...

Beauty! Thanks for posting!

Anonymous said...

Thanks a million. That's just saved me a lot of time.

Anonymous said...

Hey - I am definitely glad to find this. cool job!

Anonymous said...

Thanks -- I was having exactly the same problem.