簡體   English   中英

Bash,Gnuplot:將一個數據文件中的多個選定列對繪制到一個圖中

[英]Bash, Gnuplot: plot multiple chosen column pairs from one datafile into one plot

我正在制作一個腳本,以在窗口中繪制數據文件的所需列對。 但是我不知道如何使gnuplot接受using命令的參數。

我的代碼看起來像這樣

#!/bin/bash
filee=$1
shift 1
cols=$@

gnuplot -p << eof
#TESTS--------------------------------
print "gnuplot--starts----------------"

print "cols-var is:     $cols"
print "filee-name is:   $filee"

print "pair-vars are:"
do for [pair in "$cols"] {print pair}

print "-------------------------------"
#END TESTS----------------------------"


set term wxt 1 size 1500,900 title 'columns of $filee'
set key top left
set grid
set xrange [2:8]
set yrange [-0.02:0.02]
set format y "%g"
plot for [pair in "$cols"] '$filee' u pair  
eof

如果不是pair作為參數u我用1:31:2或不管我拿到地塊的正確數目,但當然,他們都是相同的。 我嘗試了很多東西,一切似乎除了將要工作u不接受一個變量。 運行此命令的輸出是:

$ ./cploter written.dat 1:2 1:3 1:4
gnuplot--starts----------------
cols-var is:    1:2 1:3 1:4
filee-name is:  written.dat
pair-vars are:
1:2
1:3
1:4
-------------------------------
         line 0: warning: Skipping data file with no valid points
         line 0: warning: Skipping data file with no valid points
         line 0: warning: Skipping data file with no valid points 

對於此問題的一些幫助將不勝感激:)

編輯:作為u似乎並沒有被接受,通過它的參數我選定了下面的代碼回路。 如果您知道將所需的列對繪制到一個圖中的另一種方法,請發表評論或回答:)

#!/bin/bash
fil=$1; xx=$2; y1=$3; y2=$4
gnuplot -p <<- eof
set term wxt 1 size 1500,900 title 'columns of $filee'
set key top left
set format y "%g"
plot for [i=${y1}:${y2}] '$fil' u ${xx}:i w l t 'Column ${xx}:'.i
eof

我使用gnuplot 4.6。 由於某些原因,在這種情況下無法使用for [i in $range] 使用變量ys(i)=word("$yes",i), xs=word("$xes",i)plot for [i=1:3] '$fil' u xs(i):ys(i) wl也不起作用。

(部分答案;還有其他一些方法可以解決這種情況)

運行腳本時出現另一個錯誤(gnuplot 5.0)

line 0: warning: no column with header "1:2"

但我認為問題的根源是相同的。 問題是gnuplot正在尋找名稱為“ 1:2”的單列,而不是using規范將標記“ 1:2”解釋為兩列。

如果只想繪制1:2形式的對,則可以將第二列索引作為參數傳遞給腳本,並使用plot命令

plot for [pair in "$cols"] '$filee' u 1:column(int(pair))

使用[pair in "$cols"]可以很好地工作,只要其余所有內容都正確。 以下示例可以正常工作:

文件test.dat

1 2 3 4
5 6 7 8
9 10 11 12

和腳本plot.sh

#!/bin/bash
filee=$1
shift 1
cols=$@

gnuplot -p <<EOF
set terminal pngcairo
set output 'test.png'
plot for [col in "$cols"] '$filee' u 1:(column(int(col)))

EOF

用以下命令調用此腳本

./plot.sh test.dat 2 3 4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM