Transparency for specific values in matrix using Gnuplot while preserving the palette?

痴心易碎 提交于 2019-12-02 02:36:26

You can achieve that by giving the respective pixel a value of 'NaN':

value = 123456789.0
plot "foo.dat" binary array=384x384 format='%double' \
     using ($1 == val ? NaN : $1) with image

Note, that this depends on the selected terminal. It works at least with wxt, pdfcairo, pngcairo and png, and does not work with x11 and postscript. I didn't test other terminals.

Here is a self-contained example. The background color is set to show that the pixel indeed is transparent and not white:

set xrange [0:1]
set yrange [0:1]
set isosamples 11
set samples 11
plot '++' using 1:2:($1 == 0.5 && $2 == 0.5 ? NaN : $1) with image

The result with 4.6.5 is:

Using your example data file, the following script works fine and gives a nice result:

set terminal pngcairo size 800,800
set output 'foo.png'
set size square

f(x)=1.5-4*abs(x)
set palette model RGB
set palette functions f(gray-0.75),f(gray-0.5),f(gray-0.25)

val = 1234567890.0

set autoscale xfix
set autoscale yfix
set cbrange [-10000:10000]
plot 'foo.dat' binary array=(512,512) format='%double' using ($1 == val ? NaN : $1) with image notitle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!