2015-12-11 27 views
3

讓我們說我有以下簡單的gnuplot文件:gnuplot的:一個繪圖命令的禁用部分

set term pdf 
set output "test.pdf" 

plot\ 
    sin(x),\ 
    cos(x),\ 
    0.5 

現在我只想暫時發表意見符合cos(x),\

但是,使用註釋字符#會導致錯誤的gnuplot命令。

我正在尋找解決方案而不移動代碼行。我只想使用我的編輯器的切換評論功能。

+0

有沒有辦法得到這個,請參閱http://stackoverflow.com/q/30868244/2604213 – Christoph

+0

這太糟糕了。我認爲這將是gnuplot的一個很好的擴展,可以在註釋中選擇性地禁用行延續。 – Hotschke

+0

也有關於郵件列表的討論:http://gnuplot.10905.n7.nabble.com/line-continuation-of-comments-td11266.html http://gnuplot.10905.n7.nabble.com/Comments -and-continuation-lines-td19020.html – Hotschke

回答

4

這是一種解決方法。您可以動態解析腳本以刪除#的行。使用grep

grep -v "#" script | gnuplot 

將成功地解析此:

plot\ 
    sin(x),\ 
    #cos(x),\ 
    0.5 

其中script是包含上述代碼的文件的名稱。

+0

這是一個很好的解決方法。感謝分享。 – Hotschke

0

雖然gnuplot不直接支持您要求的內容,但您大概可以構建解決方法。 作爲gnuplot的不繪製未定義的值,這可能工作

identity = 0 
#identity= 1 
name=identity ? "cos(x)" : '' 

plot sin(x), (1/identity)*cos(x) t name 

根據是否開啓或關閉評論,變量identity將具有價值01
在第一種情況下(即,identity = 0),(1/identity)(因此(1/identity)*cos(x))的結果未定義,並且gnuplot不會繪製它。
刪除上面示例中的註釋identity將等於1。在這種情況下,(1/identity)的結果是1,因此(1/identity)*cos(x)cos(x)相同。

以顯示正確的標題(identity = 1)或無標題所有的(如果identity=0),我添加了這行name=identity ? "cos(x)" : ''