Search code examples
gnuplot

Gnuplot logarithmic color scale


I've been making 2D plots of patterns using GNUPLOT, but, I need the color to be in a logarithmic scale, but only the color, not the numeric values and their corresponding tics in the color column. Is there a way to do that?

Here I have an example of one data file for generating the image. In GNUPLOT I use the following commands (or script):

set size square 1,1
set cbrange [0:2]
set pm3d map
set palette defined ( 0 'gray30', 0.75 'gray20', 1.35 'cyan')
splot 'Sq.dat' with pm3d

Example of a image that is created


Solution

  • In the gnuplot console check help palette and help palette functions. There is the option functions. For each of the color components (R,G,B) you define a function which has the variable gray as input (range [0:1]) and should have a range [0:1] as output. If you type test palette you can check the palette output.

    If all your functions for R,G,B start from 0 this will be black. If the functions for G and B end at 1 and R stays at 0, this will by cyan.

    There are also 37 predefined functions when using the option set palette rgbformulae: check help palette rgbformulae and show palette rgbformulae.

    Examples:

    # Linear:
    set palette functions  0, gray, gray
    test palette
    

    enter image description here

    # Square:
    set palette functions  0, gray**2, gray**2
    test palette
    

    enter image description here

    # Square Root:
    set palette functions  0, sqrt(gray), sqrt(gray)
    test palette
    

    enter image description here

    # Some logarithm: (play with x0)
    f(x,x0) = log((x+x0)/x0)/log((1+x0)/x0)
    x0 = 0.01
    set palette functions  0, f(gray,x0), f(gray,x0)
    test palette
    

    enter image description here

    Addition: (your data with logscale cb)

    Script:

    ### logscale cb
    reset session
    
    FILE = "SO76096868.dat"
    
    set size ratio -1
    set palette functions 0, gray**2, gray**2
    # set palette rgbformulae 33,13,10     #  alternatively, multiple colors
    
    set view map
    set logscale cb
    set format cb "10^{%T}"
    set xrange [:] noextend
    set yrange [:] noextend
    
    splot FILE u 1:2:3 w pm3d
    ### end of script
    

    Results:

    enter image description here

    enter image description here