5

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 Answer 1

3

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.

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

6 Comments

Thanks for your answer! As I don't know the names of the source, I adapted the routine that writes the datafile. Now I simply have a column for each source (ValueA, ValueB, ...) and plot it with [plot 'file.csv' u 2:1 title 'A', 'file.csv' u 3:1 title 'B', ...
See also How to use one of the column of data as legend in gnuplot? for an example how to extract the unique values of a column.
plot for [s in 'a b c d e f g'] sprintf("<(grep -v '%s$' testdata1.dat)", s) u 1:3 w l ..... I am getting error: Invalid expression at s. The version is 4.0...why??
I have tested the same in windows with 5.0 version but there I am receiving error: can not pipe data....is the piping syntax is different in windows???
I'm not sure if this will work on Windows without bash and grep installed (and running gnuplot from bash with grep in the PATH). There might be some other syntax for pipes on Windows but I'm not sure.
|

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.