2017-01-22 23 views
1

要命令直接通過不使用它的提示指定的參數使用Gnuplot(16.04在Linux Ubuntu的),我進入這個例如:使用GNUPLOT命令,而不提示

gnuplot -e "filename='DataFile.txt'" SettingsFile 

SettingsFile看起來是這樣的:

plot filename with lines 
set title "Total Packets consumption" 
set xlabel "Time" 
set ylabel "Packets" 
set datafile separator "," 
pause -1 

而且DataFile.txt看起來是這樣的:

包,時間(秒):

13392,120 
24607,240 
23867,360 
21764,480 
20727,600 
20004,720 
19719,840 
19758,960 
19728,1080 
20168,1200 
19737,1320 
19729,1440 
20135,1560 
20006,1680 
21301,1800 
19923,1920 
20002,2040 
19761,2160 
20918,2280 
22756,2400 
22820,2520 
23370,2640 
22987,2760 
22956,2880 
24427,3000 
23527,3120 
24009,3240 
23832,3360 
23464,3480 
23652,3600 
11212,3654 

第一個問題:

有沒有一種方法來設置成SettingsFile一個PNG OUTPUTFILE?因此,我可以將它作爲Gnuplot命令的參數輸入,就像我對DataFile所做的一樣。 (我想用這種方式,因爲我想從外部代碼調用它)

我要實現的是這樣的:

gnuplot -e "filename='DataFile.txt'" SettingsFile OutputFile.png 

第二個問題:

屏幕我從gnuplot的獲取輸出不同顯示xtics於預期:

enter image description here

另請注意,軸標題未顯示!

現在,如果我嘗試調整窗口,我得到這個:

enter image description here

圖形被翻轉奇怪,與標題設置,並根據需要被更新的抽動。

我應該如何解決這兩個問題,首先在SettingsFile中提到一個輸出文件,其次xtics沒有正確顯示,並在屏幕輸出中顯示第三個奇怪的行爲?

+0

和哪個os?可以(?)有所作爲。 – kebs

+0

我會問另一篇文章中的第二個問題。另外,你使用的是哪個版本的gnuplot和哪個終端(wxt,qt,x11)?注意''set datafile separator',''應該在'plot'命令之前進行(對於'xlabel','ylabel'和'title'命令也是如此)。對於第一個問題,嘗試[傳遞命令行參數到gnuplot](http://stackoverflow.com/a/31815067/2174266) – vagoberto

+0

@kebs:使用'linux'標記,我用完整的操作系統信息更新了我的問題。 – AymenDaoudi

回答

2

有幾個命令可以通過分號被添加到gnuplot -e,例如:

gnuplot -p -e 'filename="data.txt"; fileout="image.png"' SettingsFile 

SettingsFile應該已經有一個線配置終端類型:

set terminal png 
set output fileout 

set title "Total Packets consumption" 
set xlabel "Time" 
set ylabel "Packets" 
set datafile separator "," 

plot filename using 2:1 with lines 

如果您想了解更多控制你的代碼,試試這個腳本(gnuplot 5.0+):

filename=(ARGC>0 ? ARG1 : 'DataFile.txt') # By default filename=DataFile.txt 
              # If called with one argument (ARGC=1) 
              # then `filename=ARG1` 

if(ARGC>1){ 
    # if called with two arguments (ARGC=2), then configure a png output 
    set terminal png 
    set output ARG2 
} 

set title "Total Packets consumption" 
set xlabel "Time" 
set ylabel "Packets" 
set datafile separator "," 

# the plot command ALWAYS at the end of the script after the settings 
plot filename using 2:1 with lines 
  • 如果您想繪製'DataFile。txt'(默認情況下):

    gnuplot -p SettingsFile 
    
  • 如果您想繪製另一個文件, AnotherData.txt

    gnuplot -p -c SettingsFile AnotherData.txt 
    
  • 如果你想繪製另一個文件並將其保存爲PNG:

    gnuplot -p -c SettingsFile AnotherData.txt Output.png 
    

-p參數,您主要的gnuplot程序退出後,圖形窗口的生存。使用gnuplot的「調用」機制,使用參數加載腳本-c並將其餘的命令行作爲參數傳遞給它。請參閱How to pass command line argument to gnuplot?

請注意,您的腳本首先繪製數據文件,然後配置標籤,標題和datafile separator。這就是爲什麼你看到奇怪的抽搐。

+0

正如我在問題中提到的,我想從外部程序/代碼(例如Java)執行該命令。沒有腳本的情況下輸入output.png參數的任何方法? – AymenDaoudi

+0

我從C++和Fortran執行類似的命令。我不明白爲什麼它不適合你的情況。無論如何,如果你堅持你的方法,托盤與像'gnuplot -e「文件名='DataFile.txt';輸出='image.png'」SettingsFile' – vagoberto

+0

我知道它會工作,但我的解決方案將部署如此我想避免強迫他們去運行其他任何東西。但是,您的解決方案正常工作,請考慮將其添加到答案中。 – AymenDaoudi