2

I have a file that looks like

$cat myfile.dat

1 8 32 19230 1.186 3.985
1 8 64 9620 0.600 7.877
1 8 128 4810 0.312 15.136
1 8 256 2410 0.226 20.927
1 8 512 1210 0.172 27.708
1 8 1024 610 0.135 35.582
1 8 2048 310 0.121 40.172
1 8 4096 160 0.117 43.141
1 8 8192 80 0.112 44.770
.....
2 8 16384 300 0.692 6.816
2 8 32768 150 0.686 6.877
2 8 65536 80 0.853 5.904
2 10 320 7830 1.041 4.575
2 10 640 3920 0.919 5.189
2 10 1280 1960 0.828 5.757
2 10 2560 980 0.773 6.167
2 10 5120 490 0.746 6.391
2 10 10240 250 0.748 6.507
2 10 20480 130 0.770 6.567
....
3 18 8192 10 1.311 12.759
3 20 32 650 1.631 3.978
3 20 64 330 0.838 7.863
3 20 128 170 0.483 14.046
3 20 256 90 0.508 14.160
3 20 512 50 0.559 14.283
3 20 1024 30 0.665 14.405
3 20 2048 20 0.865 14.782
3 20 4096 10 0.856 14.932
3 20 8192 10 1.704 14.998

As you can see, there are many ways of plotting this information depending on the column we want as x axis. One of the ways I would like to plot the information is the 6th against the 1st column

p "myfile.dat" u 1:6

enter image description here

My main questions is if there is a way to plot those bars as solid boxes since we are only interested in the peak value achieved and not the frequency or density region of the dots.

2 Answers 2

2

Gnuplot has the smooth option, which can be used e.g. as smooth frequency to sum all y-values for the same x-value. Unfortunately there is no smooth maximum, which you would need here, but one can 'emulate' that with a bit of tricking in the Using statement.

reset
xval = -1000
max(x, y) = (x > y ? x : y)
maxval = 0
colnum = 6

set boxwidth 0.2

plot 'mydata.dat' using (val = column(colnum), $1):\
     (maxval_prev = (xval == $1 ? maxval : 0), \
      maxval = (xval == $1 ? max(maxval, val) : val),\
      xval = $1, \
      (maxval > maxval_prev ? maxval-maxval_prev : 0)\
     ) \
     smooth frequency lw 3 with boxes t 'maximum values'

Every using entry can consist of different assignments, which are separated by a comma.

If a new x value appears, the variables are initialized. This works, because the data is made monotonic in x by smooth frequency.

If the current value is bigger than the stored maximum value, the difference between the stored maximum value and the current value is added. Potentially, this could result in numerical errors due to repeated adding and subtracting, but judging from you sample data and given the resolution of the plot, this shouldn't be a problem.

The result for you data is: enter image description here

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

1 Comment

@_Christoph: Thanks for that. It is indeed very useful to know how to calculate maximums.
1

You can search for the maximum and plot only that, but this is probably easier, even if it draws lots of boxes one over another:

plot "myfile.dat" using 1:6:(.1) with boxes fillstyle solid

2 Comments

@_choroba what exactly is the :(.1) doing?
@Manolete: The third number specifies the width of the boxes.

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.