2016-10-02 41 views
0

在GNUPLOT,我可以自動設置圖例在如繪圖命令title columnhead選項:GNUPLOT AUTO SET xlabel(或ylabel),從CSV的列頭讀取文件時

plot 'test.txt' using 0:1 w linespoints title columnhead 

,所以它讀取列從CSV文件中獲取名稱並在圖例中使用它。

enter image description here enter image description here

我想同樣的設置xlabel和ylabel。有可能嗎?

(另外,我想知道一個人如何在Python做這樣的事情。它比GNUPLOT更好嗎?我應該學習Python呢?)

+0

不,gnuplot的不支持從數據文件中讀取'xlabel'和'ylabel'。你需要通過'system'使用shell命令自己完成。 – Christoph

回答

0

由@Christoph指出的那樣,system命令可能是唯一可行的解​​決辦法 - 你的具體情況,你可以這樣做:

fname="test.txt" 

getTitle(colNum)=system(sprintf("head -n1 '%s' | cut -f%d -d';'", fname, colNum+1)) 

set xlabel getTitle(0) 
set ylabel getTitle(1)