Search code examples
gnuplotpalette

Gnuplot, multiple splots with different color palette


I have two 3d surfaces. Is it possible to use a different color palette for each surface with splot? The script that i used and the graph that is produced follow:

set title "Thermal efficiency versus turbine inlet temperature and degree of superheating diagram"
    
set termopt enhanced 

set grid

set key top left

set xlabel "ΔT_{super} [^{o}C]"
set ylabel "T_{3} [^{o}C]"
set zlabel "n_{th} [-]"

#set datafile missing '0.000000000000000000e+00'
#set datafile missing '0.000000'

set hidden3d 
set pm3d 
set view 60,60

set palette rgb 7,5,15 #black-blue-red-yellow

splot "para_sub_dtsuper_iso_dtppreg_1.txt" using ($1):($2-273.15):($5) title "Conventional ORC" with lines lt 1 lw 1.5,\
      "para_sub_dtsuper_iso_dtppreg_1.txt" using ($1):($2-273.15):($6) title "Regenerative ORC" with lines lt 1 lw 1.5,\

pic_1

On a side not, i would like to know if it is possible to produced mesh color-gradient surfaces like in the picture below:

pic_2

Thank you in advance.


Solution

  • Here is a revised version of the plot that theozh linked to. It shows two surfaces in the same plot, one using color mapping via the built-in palette mechanism and the other effectively doing the same sort of color mapping explicitly. The development version of gnuplot has automated this so that you can construct and use multiple palettes by assigning a name to each one.

    #
    # Demonstrate construction and use of a separate palette
    #
    #       This method works 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 [0:5]
    blues_min = 0
    blues_max = 5
    
    #
    # 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]
    
    F1(x,y) = sqrt(x*y)
    F2(x,y) = (x*y)**(1./3)
    
    set samples 41; set isosamples 41
    set cbrange [0:5]; set xrange [0:5]; set yrange [0:5]
    set palette cubehelix negative
    unset colorbox
    
    # Needed for proper occlusion of hidden surface
    set pm3d depthorder
    # Place a thin border around each facet of the surfaces
    set pm3d  border lc "black" lw 0.5
    
    set title "Top surface uses hand-constructed 'blues' palette via rgb variable\n".\
              "Bottom surface uses 'set palette cubehelix negative'"
    set title offset 0,1
    
    splot '++' using 1:2:(F1($1,$2)):(blues(F1($1,$2))) with pm3d lc rgb variable \
               title "F1(x,y) using 1:2:3:4 with pm3d lc rgb variable", \
          '++' using 1:2:(F2($1,$2)) with pm3d \
               title "F2(x,y) using 1:2:3 with pm3d"
    

    enter image description here