Gnuplot:使用调色板时数据点的透明度

Gnuplot: transparency of data points when using palette

有没有办法在使用调色板时绘制透明数据点?

我目前有以下代码:

set style fill transparent solid 0.2 noborder
set palette rgb 22,13,-22
plot 'mydata.dat' u 1:2:3 ps 0.3 palette

我的感觉是透明度被 plot 命令的参数覆盖了。

Is there a way to plot transparent data points when using palette?

如果您选中 help palette,您将找不到(或者我忽略了)有关调色板透明度的声明。看起来您可以用不同的方式为 RGB 设置调色板,但不能为 ARGB(A=alpha 通道用于透明度)设置调色板。因此,我认为调色板不可能具有透明度(如果我错了请纠正我)。 作为解决方法,您必须通过设置具有一定透明度的颜色来设置透明度 "manually"。 您可以通过键入 show palette rgbformulae.

找到调色板背后的公式

以下示例创建了一个图,其中随机点位置在 xrange[0:1]yrange[0:1] 中,随机点大小(从 2 到 6)和随机透明度(从 0x000xff).颜色由x根据你的"manual palette"决定。我希望你能根据你的需要改编这个例子。

代码:

### "manual" palette with transparency
reset session

# These are the rgb formulae behind palette 22,13,-22
set angle degrees
r(x) = 3*x-1 < 0 ? 0: (3*x-1 > 1) ? 1 : 3*x-1
g(x) = sin(180*x)
b(x) = 1-(3*x-1) < 0 ? 0: (1-(3*x-1) > 1) ? 1 : 1-(3*x-1)

set xrange [0:1]
set yrange[-0.1:1.1]

RandomSize(n) = rand(0)*4+2              # random size from 2 to 6
RandomTransp(n) = int(rand(0)*0xff)<<24  # random transparency from 0x00 to 0xff
myColor(x) = (int(r(x)*0xff)<<16) + (int(g(x)*0xff)<<8) + int(b(x)*0xff) + RandomTransp(0)

set samples 200
plot '+' u (x=rand(0)):(rand(0)):(RandomSize(0)):(myColor(x)) w p pt 7 ps var lc rgb var not

### end of code

结果:

开发版本 5.5 的新答案

新函数set colormap允许定义透明调色板。首先,以通常的方式定义完全不透明的调色板,然后创建它的副本并为所有点添加透明度:

set palette rgb 22,13,-22
set colormap new MYPALETTE
transparency = 0.5
do for [i=1:|MYPALETTE|] {MYPALETTE[i] = MYPALETTE[i] + (int(transparency*0xff)<<24)}
func(x,y) = x*y
splot func(x,y) w pm3d fillcolor palette MYPALETTE

当然,这也适用于积分,你的命令是 plot 'mydata.dat' u 1:2:3 ps 0.3 lc palette MYPALETTE