问题
What I basically want to do is basically the same as the solution to this question
Gnuplot 5.2 splot: Multiple pm3d palette in one plot call
, but which works with pm3d. If you read the comment to that answer, the answerer said that the solution does not work if he used pm3d. Also, would it be possible to define the palette in a simpler manner, such as set palette defined ()
?
回答1:
The development branch of gnuplot supports multiple named palettes. The method shown here, however, works on earlier versions of gnuplot also. It uses the fill style to provide a color (rather than the pm3d palette), and shows how to define the fill colors so that they mimic set palette defined()
. This demo constructs only one mapping, but you could define several mappings each with its own array of colors and mapping function to use them.
This demo is extracted from the full demo for named palettes in the development branch. If you are interested you can find the full demo here: 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($1,$2)):(blues(foo($1,$2))) with pm3d fillcolor rgb variable \
title "pm3d using 1:2:3:4 with pm3d fillcolor rgb variable"
回答2:
Maybe you could define the palette differently with set palette defined
but then you probably would have to combine your 3 palettes into 1 palette and you would lose "color resolution", as far as I know a palette has 256 color steps. To be honest, I haven't thought about this in detail.
I checked again the code you referenced... apparently an additional line will do the "trick". Then you can plot with pm3d
.
set pm3d depthorder
Code: (slightly modified code from here: https://stackoverflow.com/a/57501649/7295599)
### 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($3)) w pm3d lc rgb var notitle, \
$Data02 u 1:2:3:(MyPalette02($3)) w pm3d lc rgb var notitle, \
$Data03 u 1:2:3:(MyPalette03($3)) w pm3d lc rgb var notitle
### end of code
Result:
来源:https://stackoverflow.com/questions/64091786/plotting-multiple-pm3d-surfaces-each-having-its-own-palettes-in-gnuplot