在 gnuplot 中绘制多个 pm3d 表面,每个表面都有自己的调色板

Plotting multiple pm3d surfaces each having its own palettes in gnuplot

我基本上想做的和这道题的解法基本一样 ,但它适用于 pm3d。如果您阅读对该答案的评论,回答者说如果他使用 pm3d,该解决方案将不起作用。另外,是否有可能以更简单的方式定义调色板,例如 set palette defined ()?

也许您可以使用 set palette defined 以不同方式定义调色板,但您可能必须将 3 个调色板组合成 1 个调色板,并且您会失去“颜色分辨率”,据我所知,一个调色板有 256颜色步骤。老实说,我还没有仔细想过这个。

我再次检查了您引用的代码...显然,多加一行就可以解决问题。然后你可以绘制 with pm3d.

set pm3d depthorder 

代码:(这里的代码略有修改:

### multiple "palettes" within one splot command
reset session

set samples 101,101
set isosamples 101,101 

f(x,y) = sin(1.3*x)*cos(0.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x)
set table $Data01
    splot f(x,y)
unset table

g(x,y) = y
set table $Data02
    splot g(x,y)
unset table

h(x,y) = 0.5*x
set table $Data03
    splot h(x,y)
unset table

Zmin = -3
Zmax= 3

set xrange[-5:5]
set yrange[-5:5]
set zrange[Zmin:Zmax]
set hidden3d
set angle degree

Frac(z) = (z-Zmin)/(Zmax-Zmin)
# MyPalette01
Red01(z) = 65536 * ( Frac(z) > 0.75 ? 255 : int(255*abs(2*Frac(z)-0.5)))
Green01(z) = int(255*sin(180*Frac(z)))*256
Blue01(z) = int(255*cos(90*Frac(z)))
MyPalette01(z) =  Red01(z) + Green01(z) + Blue01(z) 

# MyPalette02
Red02(z)   = 65536 * int(255*Frac(z))
Green02(z) = 256 * (Frac(z) > 0.333 ? 255 : int(255*Frac(z)*3))
Blue02(z)  = (Frac(z) > 0.5 ? 255 : int(255*Frac(z)*2))
MyPalette02(z) =  Red02(z) + Green02(z) + Blue02(z) 

# MyPalette03
Red03(z)   = 65536 * (Frac(z) > 0.5 ? 255 : int(255*Frac(z)*2))
Green03(z) = 256 * (Frac(z) > 0.333 ? 255 : int(255*Frac(z)*3))  
Blue03(z)  = int(255*Frac(z)) 
MyPalette03(z) =  Red03(z) + Green03(z) + Blue03(z) 

set pm3d depthorder
unset colorbox 

set view 44,316
splot $Data01 u 1:2:3:(MyPalette01()) w pm3d lc rgb var notitle, \
      $Data02 u 1:2:3:(MyPalette02()) w pm3d lc rgb var notitle, \
      $Data03 u 1:2:3:(MyPalette03()) w pm3d lc rgb var notitle
### end of code

结果:

gnuplot 的开发分支支持多个命名调色板。然而,此处显示的方法也适用于早期版本的 gnuplot。它使用填充样式来提供颜色(而不是 pm3d 调色板),并展示如何定义填充颜色以使其模仿 set palette defined()。该演示仅构建一个映射,但您可以定义多个映射,每个映射都有自己的颜色数组和映射函数以使用它们。

此演示摘自开发分支中命名调色板的完整演示。如果您有兴趣,可以在此处找到完整的演示: Version 5.5 named palette demo

#
# Demonstrate construction and use of a separate palette
# Ethan A Merritt - May 2020
#
# Method 1:
#       The first method works also in 5.2 but requires "lc rgb variable"
#       rather than the more natural "fillcolor rgb variable".
#       "set pm3d interpolate" breaks the color mapping of this method

#
# This creates a palette equivalent to
#       set palette defined (0 "dark-blue", 1 "white")
#
array blues[256]
do for [i=1:256] {
    blues[i] = int( (0x7f + (i-1)/(255.) * 0xffff80) );
}

#
# This is the equivalent of
#       set cbrange [-1:1]
blues_min = -1
blues_max = 1

#
# This function maps z onto a palette color
#
blues(z) = (z <= blues_min) ? blues[1] \
         : (z >= blues_max) ? blues[256] \
         : blues[ floor(255. * (z-blues_min)/(blues_max-blues_min)) + 1]

foo(x,y) = sin(x*y)

set samples 41
set isosamples 41
unset colorbox
set cbrange [-1:1]
set xrange [0:5]; set urange [0:5]
set yrange [0:5]; set vrange [0:5]

set title "Use hand-constructed 'blues' palette via rgb variable"

splot '++' using 1:2:(foo(,)):(blues(foo(,))) with pm3d fillcolor rgb variable \
           title "pm3d using 1:2:3:4 with pm3d fillcolor rgb variable"