1

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.

6
  • 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? Commented Mar 24, 2021 at 11:45
  • 1
    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. Commented Mar 24, 2021 at 12:18
  • @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. Commented Mar 25, 2021 at 5:39
  • 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. Commented Mar 26, 2021 at 10:56
  • 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. Commented Mar 26, 2021 at 10:56

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much! This is exactly what I needed!
You're welcome! Which version is your preference? The first solution with transposed data or the somehow strange second version? Can you change/transpose your data or is the data fixed?
The first solution imho is the most logical and optimal. No need to transpose data if you are the one who make the origin data files ))) The suggested data structure in my question wasn't optimal to solve the problem. I use the first solution, the only difference on my PC is that the $0 returns the name of the bash script file, I used (column(0)+1) instead.
@skobyakov right, I didn't think about bash. You can also simply use (column(0)) or even just 0 without +1 it doesn't matter because you have xtic(1) as xtic labels. In the above example the +1 was necessary because I used the same xrange for both solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.