1
votes

How can I plot a comparison graph of two values from the file (first row - titles, second row - values, third row - uncertainties):

value1 value2
6,7147 6,7131
0,0036 0,0102

To get this graph:

enter image description here

Under linux (bash script), using gnuplot.

1
What have you tried? What research did you do? Did you find any relevant documentation? Did you read it and try to implement it? - KamilCuk
I did not find the exact solution. Unfortunately, I do not know gnuplot well and hope that someone with solid gnuplot background can just write the script down right away. - skobyakov
@skobyakov So, you haven't even tried by checking the gnuplot homepage or tutorial? People on StackOverflow don't appreciate it if they don't see your own coding effort even if it does not give the desired results. Otherwise we could think that you are just too lazy and it's more convenient if somebody else does the work. StackOverflow is not a coding service but a place to improve coding skills. Question: Why is the errorbar for value2 smaller than the errorbar for value1? And the error bar values also don't seem to be consistent with your data. Anyway, see my answer. - theozh
Dear @theozh, of course I tried. I spend the whole day to figure out how it works, but I did not get it to work exactly how I like. I do not code every day, it is not my profession. Thank you for your help. Please consider this as a help since you haven't made a part of my work. You can see it as a promotion of open-source tools. They work good, but unfortunately, some of them are too complicated to get things done in a few minutes without solid skills. - skobyakov
The uncertainties are different because the values has been measured using different techniques. Uncertainties are characteristic for each separate measurement, and sometimes uncertainty is way too large which means that there is a problem with the measurement itself or points to a possibility of error in calculations. - skobyakov

1 Answers

1
votes

Your data format is a bit unfortunate. In this case it would be better if the data was transposed. Unfortunately, gnuplot doesn't have a built-in transpose function. So, if you can't transpose your data with some other tools, the gnuplot commands for plotting this data will get a bit cumbersome. Maybe there is an easier solution which I am currently not aware of.

Next thing is that you have comma as decimal separator in the input format. Standard in gnuplot is decimalpoint (check help decimalsign). You can change it by set decimalsign locale "<...>", e.g. french or german or maybe others should work, depending on what you have installed. Check the following code example.

Code:

### yerrorbar with row data
reset session

# data format easy for gnuplot
$Data1 <<EOD
value1  6,7147  0,0036
value2  6,7131  0,0102
EOD

# data format difficult for gnuplot
$Data2 <<EOD
value1  value2
6,7147  6,7131
0,0036  0,0102
EOD

unset key
set decimalsign locale "french"     # or "german" should also work
set xrange [0.5:2.5]

plot $Data1 u ($0+1):2:3:xtic(1) w yerrorbar pt 5 lc "red" notitle

pause -1    # wait until OK pressed

plot for [i=1:2] y2=y1=NaN $Data2 u (i):(y0=y1,y1=y2,y2=column(i),y1):(y2):xtic(columnhead(i)) w yerrorbar pt 5 lc "blue"
### end of code

Result:

enter image description here

enter image description here