3
votes

I am plotting a couple of lines in a certain data set. A couple of the data points (column 13 in the example below) are special, I want them to be marked with a circle and labeled (the labels are in column 12).

plot "data.csv" using 0:13 with circles lt 3 fs transparent solid 0.3 noborder notitle,\
"data.csv" using 0:13:(sprintf("(%d, %d)", $1, $12)) with labels nopoint offset char 1,-2 notitle,\
"data.csv" using 0:6 with lines lt 7 lw 2

I already figured out how to do that. Unfortunately the labels do overlap sometimes, which makes them unreadable. How can I make the labels appear alternating above/below the data points? I tried to define a function that switches between -1/1, but failed to do so. I also tried to make the offset random by adding

"data.csv" using 0:13:(sprintf("(%d, %d)", $1, $12)) with labels nopoint offset char 1,int(-5*(rand(0))) notitle

but that also did not work (no visible effect).

Below is an example how the current version looks like (with a couple more plotted lines, I tried to keep the code sample short). Appreciate any help...

enter image description here

1

1 Answers

4
votes

Try to separate the data points into two sets with every:

plot "data.csv" using 0:13 with circles lt 3 fs transparent solid 0.3 noborder notitle,\
"data.csv" using 0:13:(sprintf("(%d, %d)", $1, $12)) every 2::0 with labels nopoint offset char 1,-2 notitle,\
"data.csv" using 0:13:(sprintf("(%d, %d)", $1, $12)) every 2::1 with labels nopoint offset char 1,2 notitle,\
"data.csv" using 0:6 with lines lt 7 lw 2

Then every odd data point has a positive offset; every even data point has a negative offset (or odd <--> even ;-) )


Note: if you re-use the same source (file) in a comma-separated plot statement, you can use '' instead of repeating 'data.csv'.