3

I have the following data file:

denst densu densd denss
3     1     1     1
4     1     1.5   1.5
5     1     2.5   1.5

I can plot, say, densu(denst) as:

plot 'file.txt' u 'denst':'densu'

Which is very convenient syntax. But if I want to plot, say, the sum of densu and densd, with respect to denst the only way I can do it is:

set key autotitle columnhead to tell gnuplot the first line is headers and not data

plot 'file.txt' u 1:($2+$3) to plot

The question is how can I do operations with column values like that, but using the name notation? The actual file is a csv with ~40 columns, and it's very tedious to manually count which column is which number so I can use the $n syntax to do math with column data.

I would want to do something like plot 'file.txt' u 1:($'densu'+$'densd'), using header name syntax analogously to how I can do it with column number syntax. Is there any way to do this?

1 Answer 1

10

I've discovered a way to do it. These two commands are equivalent:

plot 'file.txt' u 1:($2+$3)
plot 'file.txt' u 1:(column(2)+column(3))

You can't do

plot 'file.txt' u 'denst':($'densu'+$'densd')

but you can do

plot 'file.txt' u 'denst':(column('densu')+column('densd'))

to the same effect.

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.