1

I have input file test.dat that contains

1 1
2 2
3 3 
4 4

I wrote the script for gnuplot:

gnuplot <<EOF
set term png size 1000,1000;
set output "out.png";
set arrow from graph 0,1 to graph 0,1.1 filled
set arrow from graph 1,0 to graph 1.1,0 filled
set tmargin 5
set rmargin 20
set border 3
set tics nomirror
set grid
set xtics font "Verdana,14"
set ytics font "Verdana,14"  
set nokey
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "black"
set ylabel "Efficiency, %" offset 2,0,0 font "Verdana,14"
set xlabel "Cores, N" offset 0,0,0 font "Verdana,14"
func1(x) = x / 2
func2(x) = x * 2
plot "test.dat" u (func1($1)):(func2($2)) ls 1 smooth csplines;
EOF

But the error occurs when you try to start it:

gnuplot> plot "test.dat" u (func1()):(func2()) ls 1 smooth csplines;
         line 0: invalid expression 

1 Answer 1

3

The dollar signs are interpreted as starting a shell variable. Use column instead:

gnuplot <<EOF
set term png size 1000,1000;
set output "out.png";
func1(x) = x / 2
func2(x) = x * 2
plot "test.dat" u (func1(column(1))):(func2(column(2))) ls 1 smooth csplines;
EOF
Sign up to request clarification or add additional context in comments.

2 Comments

Alternatively, escape the $ signs with a `\`.
@Joce Yes, but I prefer using column whenever the script is created automatically, because that always works regardless of how you invoke gnuplot or prepare the script.

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.