2013-01-09 58 views
4

我必須創建一個顏色映射,並且「與圖像」的繪圖樣式完全符合我的需求。 (繪製在位置x,y z的確切值,所以使用pm3d不是我的選項)Gnuplot:undefined/missing datapoints and plotting style'with image'

問題是,我的數據文件中有未定義的點。例如,函數表示質量比,因此負的z值沒有物理意義,我想省略它們。或者某些z值甚至是「NaN」。

示例數據文件:

1.0 1.0 1.5 
1.0 2.0 1.7 
1.0 3.0 1.9 
2.0 1.0 1.6 
2.0 2.0 1.8 
2.0 3.0 2.0 
3.0 1.0 1.7 
3.0 2.0 1.9 
3.0 3.0 -1.0 

所以我不想繪製值-1的位置(3,3),但留下的(3,3)空白像素。

我嘗試這樣做:

plot './test.dat' u 1:2:($3>0 ? $3 : 1/0) with image 

,但它不工作。它說:

警告:像素數不能被分解成整數匹配網格。 N = 8,K = 3

set datafile missing "NaN" 
的情況下

該-1.0通過 「南」 替換也不起作用。

我發現的唯一的另一種方法是:

set pointsize 10 
plot './test.dat' u 1:2:($3>0 ? $3 : 1/0) palette pt 5 

但然後我必須手動調整爲每個情節的pointsize,x和y的範圍和情節的大小,所以不存在任何空格或重疊數據點。 (請參閱this question。)

因此,長話短說:有沒有什麼方法可以將「帶圖像」的繪圖樣式與未定義/缺失的數據點一起使用,並將這些點保留爲白色?

回答

2

我還沒有找到一種方法來使gnuplot在這種情況下很好地處理NaN。它爲我設置爲1,這似乎很奇怪,但可能是'plot ... with image'處理丟失數據的一個特徵。

還有一個竅門,你可以使用,如果你只是想消除負數:

#!/usr/bin/env gnuplot 

set terminal png 
set output 'test.png' 

filter(x) = (x > 0) ? x : 1/0 
philter(x) = (x > 0) ? x : 0 

# just in case 
set zero 1e-20 

# make points set to zero be white 
set palette defined (0 1.0 1.0 1.0, \ 
       1e-19 0.0 0.0 1.0, \ 
        1 1.0 0.0 0.0) 

# get min/max for setting color range 
stats 'test.dat' u (filter($3)) nooutput 

# set color range so minimum value is not plotted as white 
set cbrange [STATS_min*(1-1e-6):STATS_max] 

plot './test.dat' u 1:2:(philter($3)) with image 

在您的數據文件就產生這樣的情節: enter image description here

這不是很理想的,因爲有白位在顏色欄的底部,它不處理NaN。不可能擺脫白色的原因是,在設置調色板時,所使用的數字只是自動調整以適應任何顏色條,並且調色板中有一定數量的插槽(256?)。所以,調色板中的第一個槽將始終顯示調色板開始的值(白色),而不管調色板中的下一個顏色是否顯示通過刻度的1e-19。

+0

謝謝你的回答,這是一些東西;)在pngcairo終端看起來不錯(在cb底部沒有白點)。 – Regenbogenmaschine