3

I wonder, can I used two different pm3d palettes in splot? I use Gnuplot 5.2 and want to show two 3D surfaces, like ocean and land with different color palettes. Can I define this in some way like:

splot "file" u 1:2:3 with pm3d palette 1, "file" 1:2:4 with pm3d palette 2

The data in column 1 and 2 are integers that extend from 0 to 100, they define a grid. The boundaries may be different for different maps. The z axis values are real numbers representing relative changes on logarithmic scale and extend from -10 to 10.

enter image description here

  • 1
    what are the numbers in column 3 and 4? Positive or negative? Maybe, a range from 0 to -11'000 for ocean and from 0 to +8848 for land, or something else? Can you give a few example lines? – theozh Aug 12 '19 at 18:14
  • thank you for the addition. However, it's still not clear to me. Green mesh is data from column 3 and blue mesh is data from column 4? And you want to have these two meshes with different palettes? The additional grey-scale base confuses me. Thank you for clarification. – theozh Aug 13 '19 at 08:39
  • Yes, you are correct, green is from column 3 and blue is from column 4. Here the blue is a simple plane at -3. In fact I have several surfaces like the green mesh, which I would like to show with different pm3d palettes. This will likely need a workaround as there is no such option in the documentation, afaik. The grey-scale base is something I can do now with pm3d. I can put one such map at the base (like in this case), top or on the surface, but I would like to have two or three such surfaces. Maybe I need to play with multiplot... – Peter Nemeth .malomsok. Aug 13 '19 at 13:49
  • I'm not aware that you can switch palette within the same `splot` command. Maybe some workaround might achieve a smiliar looking result. With `multiplot` you will lose interactivity (i.e. changing viewing angle in an interactive terminal by mouse), because only the last plot will be replotted. – theozh Aug 13 '19 at 13:59

1 Answers1

2

The following might be solution for you. I do not see how to change the palette within a splot command. So, the basic idea of the workaround is to set the linecolor via formulae which can be set differently for each splot-(sub)command. I hope you can adapt the example below to your needs.

Also check help rgbformulae and type show palette rgbformulae which will show you the formulae behind the palettes.

Code:

### 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 view 44,316
splot $Data01 u 1:2:3:(MyPalette01($3)) w l lc rgb var notitle, \
      $Data02 u 1:2:3:(MyPalette02($3)) w l lc rgb var notitle, \
      $Data03 u 1:2:3:(MyPalette03($3)) w l lc rgb var notitle
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • Wow, this is impressive and it does what I needed! Thank you Theozh! This workaround should be standardized and could go into Gnuplot as a built in option. – Peter Nemeth .malomsok. Aug 15 '19 at 08:07
  • 1
    Glad to hear that this is helpful to you. Apparently, however, this only works with lines. If you do `splot ... w pm3d...`, the last surface will cover all previous ones which I do not yet understand why. – theozh Aug 15 '19 at 08:48
  • ...it also works with `pm3d` if you use `set pm3d depthorder`, see https://stackoverflow.com/a/64092310/7295599 – theozh Dec 31 '20 at 09:15