Search code examples
graph3dgnuplotheatmapdefault-value

gnuplot: default value for heatmap (if no data is available)


Can you tell me how to specify the default cb (or z) value?

I build a 3d chart {x,y,z} or {x,y,cb}, but for different x there are different ranges of y, and as a result white bars are visible on the chart (for heatmap/colorbox). I would like to see no white stripes, and where there is no data, gnuplot would substitute the default value (for example, 0) and, accordingly, paint the field with the appropriate color for heatmap


Solution

  • You have several options, depending on exactly what plot mode you are using and what type of data you have. In general you can use two properties of the color assignment to get what you want:

    1) out-of-bound values are mapped to the color of the extreme min or max of the colorbar. So one option is to assign a palette that has your desired "default" color at the min and max, independent of whatever palette function you use for the rest of the range

    2) data values that are "missing" or "not-a-number" generally leave a hole in the grid of a pixel image or heat map that lets the background color show through.

    There is a demo imageNaN.dem in the standard demo set that shows use of these features for several 2D and 3D heat map commands. The output from a heatmap generated by splot $matrixdata matrix with image is shown below.You can see extreme values pinned to the min/max of the colorbar range.

    Note that if you want some color other than the backgroundn to show through, you could position a colored rectangle behind the heat map surface.

    # Define the test data as a named data block
    $matrixdata << EOD
    0    5 4 3  0
    ?    2 2 0  1
    Junk 1 2 3  5
    NaN  0 0 3  0
    Inf  3 2 0  3
    -Inf 0 1 2  3
    EOD
    
    set view map
    set datafile missing '?'
    unset xtics
    set ytics   ("0" 0.0, "?" 1.0, "Junk" 2.0, "NaN" 3.0, "Inf" 4.0, "-Inf" 5.0)
    
    set cblabel "Score" 
    set cbrange [ -2.0 : 7.0 ]
    
    splot $matrixdata matrix using 1:2:(0):3 with image
    

    enter image description here