如何将列号参数传递给 gnuplot
How to pass column number argument to gnuplot
我是运行这个脚本:
gnuplot -e "arg_xlabel='My X Label'" -e "arg_ylabel='My Y Label'" -e "arg_filename='my.csv' " -e "arg_columnindex=4" histogram.plt
除了 arg_columnindex 之外的所有参数都有效,它产生:
#!/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
如何传递列索引参数?
使用 column(arg_columnindex)
而不是 $arg_columnindex
。
除了 Ethan 对 $arg_columnindex
的提示外,您多次指定选项 -e
的原因是什么?
以下对我有用。 window 的选项 -p
持续存在(在使用 postscript 终端的情况下不需要)。
gnuplot -p -e "arg_xlabel='My X Label'; arg_ylabel='My Y Label'; arg_filename='SO70859921.dat'; arg_columnindex=4" SO70859921.gp
数据: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
代码: 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
结果:
我是运行这个脚本:
gnuplot -e "arg_xlabel='My X Label'" -e "arg_ylabel='My Y Label'" -e "arg_filename='my.csv' " -e "arg_columnindex=4" histogram.plt
除了 arg_columnindex 之外的所有参数都有效,它产生:
#!/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
如何传递列索引参数?
使用 column(arg_columnindex)
而不是 $arg_columnindex
。
除了 Ethan 对 $arg_columnindex
的提示外,您多次指定选项 -e
的原因是什么?
以下对我有用。 window 的选项 -p
持续存在(在使用 postscript 终端的情况下不需要)。
gnuplot -p -e "arg_xlabel='My X Label'; arg_ylabel='My Y Label'; arg_filename='SO70859921.dat'; arg_columnindex=4" SO70859921.gp
数据: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
代码: 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
结果: