#142 Heatmap help

closed
nobody
None
5
2012-11-23
2012-04-03
Jakob
No

I hope this is the right place for my question, if not, please redirect me! I'm trying to make a heatmap out of grided data, but i don't get it just like I want it so here it goes. If the z-value is 0 I want the corresponding square to be white, otherwise different shades of blue, this is important since I need to know if there was any data or not in a point, for this I have created palette functions which seems to be working. My code looks like this:
unset key
set cbrange [0:100]
green(x)=x==0?1:0.8-0.8*x
red(x)=x==0?1:0.8-0.8*x
blue(x)=x==0?1:1
set palette functions red(gray),green(gray),blue(gray)
set cblabel "Percentage"
set xlabel "Test time, [%]"
set ylabel "Time, [100 ms]"
set pm3d map
splot "hm_matrix_file.dat" matrix with image

and hm_matrix_file.dat contains dummy data:
99 50 1
0 0 0
1 1 1
1 50 99

When I run the script the colors are showing as expected, but each square is centered around 0, 1, 2 and so on, which makes the plot kind of uggly, instead i would like the squares from 0-1, 1-2, 2-3, etc. One way to accomplish this is to remove the "with image" option to splot, but then the colors are not right any more. Seems like gnuplot does some sort of interpolation and the zeros are not visible as white anymore, likewise the 99 is not as distinct as it should be.

Any help is apprecieated!
Jakob

Discussion

  • Ethan Merritt
    Ethan Merritt
    2012-04-03

    It is true that gnuplot draws image pixels centered about their nominal coordinate rather than drawing them with one of the corners at the nominal coordinate. You can correct for this in your image plot by saying
    set xrange [-.5:2.5]
    set yrange [-.5:2.5]
    set xtics 1
    set ytics 1
    splot "hm_matrix_file.dat" matrix with image

    However, the simpler thing is not to use pm3d + splot in the first place.
    It's really a 2D plot with explicit colors, not a 3D plot.
    So a simpler script would be:

    set key
    set cbrange [0:100]
    green(x)=x==0?1:0.8-0.8*x
    red(x)=x==0?1:0.8-0.8*x
    blue(x)=x==0?1:1
    set palette functions red(gray),green(gray),blue(gray)
    set cblabel "Percentage"
    set xlabel "Test time, [%]"
    set ylabel "Time, [100 ms]"
    set xtics 1
    set ytics 1
    set auto fix
    plot "heatmap.dat" matrix with image

     
  • Jakob
    Jakob
    2012-04-11

    Thanks a lot! However, when i use your script the squares are still centered around their nominal coordinates. The set xtics/ytics makes it much nicer by removoing fractional tics, but not nice enough! I've tried to use an offset for the tics, but if i shift them -0.5 step I don't get the largest one. Is there any way to handle this in a nice way, or do I need to manually draw all my squares in order to get them the way I want?

    /Jakob

     
  • Ethan Merritt
    Ethan Merritt
    2012-04-11

    set xtics offset first -0.5, 0
    set ytics offset first 0, -0.5

     
  • Ethan Merritt
    Ethan Merritt
    2012-11-23

    • status: open --> closed