2016-08-10 32 views
0

我有一些數據我想在gnuplot中繪製。爲了能夠繪製它們,我寫了一個名爲「plot_A.gp」的腳本。其中我設置了軸的值,標籤和輸出端子。
爲了不修改每個數據文件,我想知道是否有可能使腳本能夠處理拖放文件。爲gnuplot拖放腳本

作爲示例腳本:

set xrange [0 to 100] 
set xlabel "x-axis" 
set ylabel "y-axis" 
set terminal eps 
set output %1.pdf 
plot %1 using 1:($2*$2) with lines 

如何設置%1我剛纔滴落在腳本文件的名稱?

回答

1

請在gnuplot提示符下執行腳本call而不是loadcall最多可接受10個參數。在gnuplot 5.0之前,這些參數被稱爲$ 0,$ 1,...,$ 9。

在gnuplot的4.6,你的腳本應該是這樣的:

datafile="$0" 
outputfile="$0".".pdf" 
set xrange [0 to 100] 
set xlabel "x-axis" 
set ylabel "y-axis" 
plot "hello" using 1:($$2*$$2) with lines 
set terminal eps 
set output outputfile 
replot 
set terminal wxt 
set output 

因爲$2指的是第三個參數的腳本,訪問第二列中使用$$2代替。或者,您也可以使用1:(column(2)*column(2))

你會這樣稱呼它。

gnuplot> call "plot_A.gp" "hello" 

這將繪製文件「hello」中的數據並創建一個名爲「hello.pdf」的pdf。作爲最佳做法,我還將終端重置爲wxt

從gnuplot 5.0開始,使用$ 0,$ 1等被棄用。相反,您應該使用特殊變量ARG0,ARG2,...,ARG9。我沒有訪問gnuplot 5.0。但我認爲你只需要使用ARG0而不是$0。請你可以參考這個答案How to pass command line argument to gnuplot?