4
votes

I have the following data, which I wan't to plot using GNUPLOT:

#TIME #VALUE #SOURCE
1 100 A
1 88 B
2 115 A
2 100 B
3 130 A
3 210 B

I want to have two lines drawn, depending on the value of column #SOURCE. One line for A and one line for B. Is this possible with GNUPLOT and if yes how?

Is it possible to also draw a summation of column #VALUE depending over column #TIME? Means, that for all equal entries in #TIME, the values in #VALUE will be summed up.

Thanks in advance, Frank

1

1 Answers

2
votes

One way to do it would be to use grep to locate lines ending with A or B and plot the result. You can do this in a single plot line with a for loop if you know the characters lines will end in:

plot for [s in 'A B'] sprintf("<(grep -v '%s$' data.dat)", s) u 1:2 w l

This plots the data you provided (saved in data.dat) as two different lines.

You could also change the for part to [s in 'word1 word2 word3'] or any other string you like. If you don't know the character/word lines will be ending with you would probably need to pass the file twice first to determine the string for the for loop and a second time to do the plotting.