2013-06-05 44 views
4

我正在編寫一個腳本來一次繪製多個文件中的多個文件。我也想保存每個對應於數據文件的圖的輸出。我們怎樣才能給GNUPlot兩個參數。例如:示例GNUPlot腳本如何給命令行參數gnuplot

set xlabel "a" 
set ylabel "b" 
set zlabel "c" 
set term postscript 
set output "??" #'??' implies variable i.e. take file name from commandline 
splot "??" with points,"??" with points #'??' implies variable i.e. take file name from commandline 

並且此腳本將由另一個生成所需文件名的shell腳本運行。

任何幫助表示讚賞。

回答

8

您還可以使用gnuplot的-e命令行選項。看到這個問題的例子:How to pass command line argument to gnuplot?

+0

您是否找到'-e'選項的任何官方文檔?我正在尋找幾個小時,仍然沒有運氣。 – Wolf

+0

@Wolf您可以在gnuplot文檔中的「批處理/交互式操作」部分找到它。 – Christoph

+0

@Christoph感謝,但它仍然有點令人困惑:我發現了同一版本的文檔的兩個版本,[批處理/交互操作](http://gnuplot.sourceforge.net/docs_4.2/node46.html)和[批處理/ Interactive_Operation - Gnuplot:交互式繪圖程序](http://soc.if.usp.br/manual/gnuplot-doc/htmldocs/Batch_002fInteractive_005fOperation.html)。這是如此根本,我不能相信爲什麼這些信息是這樣隱藏的。 – Wolf

-3

試試這個簡單的bash腳本

#!/bin/bash 

file="output.png" 
infile1="$1" 
infile2="$2" 

echo " 
set xlabel \"a\" 
set ylabel \"b\" 
set zlabel \"c\" 
set term postscript 
set output \"$file\" #'??' implies variable i.e. take file name from commandline 
splot \"$infile1\" with points,\"$infile2\" with points #'??' implies variable i.e. take file name from commandline 
" > sample.gp && gnuplot sample.gp 

,並調用它像./script data.txt data2.txt 你將不得不存儲在output.png輸出和存儲在sample.gp文件gnuplot的文件。

即使每次繪製的文件數量不同,添加更多文件以繪圖也很容易。您也可以將您的.gp文件存儲在不同的輸出中。

+5

這很可怕。請不要這樣做。使用-e – easytiger