2013-01-09 46 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