1
votes

Using gnuplot I would like to plot a data set, signal vs. time (let's say a chromatogram) with different colors for selected regions of the curve (let's say peaks) but I am not sure whether it is possible or not. What I tried so far is something like:

plot [2:4.6] [0:100] 'data.csv' using 1:2 with lines lt 1,\
[4.6:4.7] [0:100] 'data.csv' using 1:2 with lines lt 2,\
[4.7:6] [0:100] 'data.csv' using 1:2 with lines lt 3

but it does not seem to work, since I only get the 'invalid expression' message.

2

2 Answers

1
votes

Use linecolor variable to dynamically specify from which line type to take the color:

lt(x) = (x >= 4.7 ? 3 : (x >= 4.6 ? 2 : 1))
plot 'data.csv' using 1:2:(lt($1)) linecolor variable
0
votes

Although the method proposed by Christoph answer is good for a limited number of color changes, it may be long and complicated to set up in my case since my real data set will have many peaks and many changes of color.

I found a better one based on this question gnuplot: yerrorbars with linecolor variable, it simply consists in using a third column (which can simply be added using a spreadsheet) to set the color of every data point with the gnuplot code:

plot [2:6] [0:100] 'data.csv' using 1:2:3 linecolor variable with lines notitle