29

Just a simple question (I imagine) but, lets say I have the following data file:

# no x data, it's sampled for instance each second. 23 42 48 49 89 33 39 44 97 

How (if possible) can I plot that as if it were

1 23 42 48 2 49 89 33 3 39 44 97 

using the 1,2,3,.. (first column) as x ?

doing something like: plot "file.dat" using (lineNumber):3 for instance.

3 Answers 3

46

If you don't want to rely on awk, gnuplot can do this as well. See help plot datafile using and help plot datafile using pseudocolumns. Try:

plot "file.dat" using (column(0)):3 
Sign up to request clarification or add additional context in comments.

3 Comments

You can even use plot "file.dat" using 0:3
Or, as pointed out in the other answer, even plot "file.dat" using 3
@vitaly -- Yep. I used this (slightly more complicated) form because it allows for more complex expressions in the using expression (e.g. scaling of the line numbers, etc.) but for simple things you're absolutely correct.
16

E.g. to plot the third line of the datafile:

plot "DATAFILE" u 3 

or with awk:

plot "<awk '{print FNR,$0}' DATAFILE" u 1:4 

Note that awk adds linenumbers, so the first column is linenumber.

does the same, gnuplot is automatically using the line-number for the x-axis

Comments

4

Or more simply, you can also type: plot "file.dat" u ($0):3

This will allow you to modify the index variable linearly, as you would any other column

Such as scaling by 2 and adding 1: plot "file.dat" u (($0)*2+1):3

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.