0

I'm running this script:

gnuplot -e "arg_xlabel='My X Label'" -e "arg_ylabel='My Y Label'" -e "arg_filename='my.csv'" -e "arg_columnindex=4" histogram.plt

All arguments work except for the arg_columnindex which yields:

#!/gnuplot
#    
# Histogram of compression ratio distribution
#
set terminal postscript enhanced landscape
set output "histogram.ps"
set size ratio 0.5
set key top right
set xlabel arg_xlabel
set ylabel arg_ylabel
set style fill solid 1.0 border -1
set datafile separator ","
binwidth=0.02 # Adjust according to distribution of values in data file 
set boxwidth binwidth * 20
bin(x,width)=width*floor(x/width) + binwidth/2
plot arg_filename using (bin($arg_columnindex,binwidth)):(1.0) smooth freq with boxes t ""
# EOF
gnuplot -e "arg_xlabel='My X Labnel'" -e "arg_ylabel='My Y Label'" -e "arg_filename='my.csv'" -e "arg_columnindex=4" histogram.plt                                                              (base) 

plot arg_filename using (bin($arg_columnindex,binwidth)):(1.0) smooth freq with boxes t ""
                              ^
"histogram.plt" line 16: Column number or datablock line expected

How can I pass the column index argument?

2 Answers 2

1

use column(arg_columnindex) instead of $arg_columnindex.

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

Comments

1

Besides Ethan's hint to $arg_columnindex, what is the reason that you are specifying the option -e multiple times? The following works for me. Option -p for window persist (not necessary in your case with postscript terminal).

gnuplot -p -e "arg_xlabel='My X Label'; arg_ylabel='My Y Label'; arg_filename='SO70859921.dat'; arg_columnindex=4" SO70859921.gp

Data: SO70859921.dat

1  0  0  6
2  0  0  4
3  0  0  7
4  0  0  1
5  0  0  3
6  0  0  2
7  0  0  5

Code: SO70859921.gp

### calling the script from command line with arguments

set xlabel arg_xlabel
set ylabel arg_ylabel

plot arg_filename u 1:(column(arg_columnindex)) w lp pt 7
### end of code

Result:

enter image description here

1 Comment

Thanks i'm new to this and this was very helpful!

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.