1

I was going through the Gnuplot in Action book, and I came across the section that talks about the "every" command. The sample data that the author uses is:

# time - value
0 100.03 # temperature
0 2.10 # pressure
1 100.26 # t
1 2.02 # p
2 101.34 # t
2 1.95 # p
3 102.41 # t
3 1.87 # p

And he plots the temperature vs. the first column of data (time) using the command:

plot "data" every 2 using 1:2 with lines

Is there a way to plot the temperature vs. the pressure without having to manipulate the file itself? In other words, is it possible to use the same column for the x and y data for a plot?

1 Answer 1

1

There is no way that I know of to do it since gnuplot reads 1 "record" at a time. You can tell gnuplot which records to read, but there's no way to tell gnuplot to mix adjacent records (other than farming out the heavy lifting to some other utility). However, since gnuplot can read the standard output of other utilities, you can do this without messing with the file located on the disk or creating any temporary files. Here's how you could do it using awk:

#untested
plot '<awk "BEGIN{getline}{a=$2;getline; b=$2;    print a,b}" test.dat' u 1:2 w lines
#          #discard header #line1        #line2  #print mix

There might be an easier way using sed, but I don't know sed as well as I know awk and this isn't too bad

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

Comments

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.