Search code examples
labelgnuplotcolorbox

gnuplot colorbox label position


I'm using the view map feature with a data set that is often whole numbers. I limit the number of colors based on the range of whole values when the range is small. I'm looking for an option that will place the value labels at the center of each colorbox color range. For example I'd like "500" to appear at the center of YELLOW rather than the top, and I'd like "498" to appear in the center of BLACK rather than the bottom.


Solution

  • # colorbox centered at screen x=0.9, 0.1 < screen y < 0.9
    # known range [0:10] allows us to calculate tic positions
    # 
    set colorbox user origin screen 0.85, 0.1 size 0.1, 0.8
    set cbrange [0:10]
    
    # custom tic labels for the colorbox
    unset cbtics
    set style textbox opaque border lc "black" margins 0,0
    
    do for [i = 1:9] {
        set label i at screen 0.9, (0.1 + 0.08*i)
        set label i sprintf("%03d",i) center boxed front
    }
    
    # some function for which the cbrange makes sense
    set palette cubehelix 
    set sample 101; set isosample 101; set xyplane 0
    f(x,y) = 10*sinc(sqrt(x*x + y*y))
    
    splot f(x,y) with pm3d
    

    enter image description here