Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label data points for cumulative plot with Gnuplot

It is straightforward to label data points in Gnuplot, in this example, I use the third column as labels for this data set (data.txt):

 1 -22 "Event 0"
 2 -139.7 "Event 3"
 3 -11 "Event 7"
 4 -35.2 "Event 6"
 5 -139.7 "Event 2"
 6 -139.7 "Event 4"
 7 -84.7 "Event 1"
 8 -22 "Event 9"
 9 -64.9 "Event 8"
 10 -38.5 "Event 5"

gnuplot> plot 'data.txt' u 1:2, "" u 1:2:3 w labels rotate offset 1

This is the result (I omitted polishing for this purpose): enter image description here

However, I need the data points plotted by cumulative sum:

gnuplot> plot 'data.txt' u 1:2 smooth cumulative

enter image description here

Now, how can I label the points at their new "coordinates"? Something like this does not work (I want the labels down in each knee of the cumulative curve):

gnuplot> plot 'data.txt' u 1:2 s cum, "" u 1:2:3 s cum w labels offset 1

enter image description here

The result should look something like this (here manually cut and positioned with Gimp): enter image description here

like image 896
smartmic Avatar asked Oct 31 '22 06:10

smartmic


1 Answers

You can plot your cumulative graph to a file, and then use those modified data as you would with a regular data file. To access the labels to can use the paste command and make use of extra columns:

set table "cumulative_labels"
plot 'data.txt' u 1:2:3 smooth cumulative w labels
set table "cumulative_data"
plot 'data.txt' u 1:2 smooth cumulative
unset table
plot 'cumulative_data' u 1:2 w l, \
"< paste cumulative_labels cumulative_data" u 4:5:3 w labels offset 1

Edit:

gnuplot-only way to do this, with no intermediate files, but dropping the smooth cumulative option:

sum = 0.
plot "data.txt" u 1:2 s cum, "" u (sum = sum + $2, $1):(sum):3 w labels offset 1
like image 183
Miguel Avatar answered Nov 15 '22 09:11

Miguel