在热图中的gnuplot值上显示标签

时间:2014-04-22 08:12:52

标签: matrix gnuplot heatmap

基于gnuplot示例关于“热映射,其中非零像素值写为标签”在此处: http://gnuplot.sourceforge.net/demo_cvs/heatmaps.html

我有数据:

6 5 4 3 1 0
3 2 2 0 0 1
0 0 0 0 1 0
0 0 0 0 2 3
0 0 1 2 4 4
0 1 2 3 4 6

和我的gnuplot:

set terminal pngcairo enhanced font "arial,10" fontscale 1.0 size 500, 350 
set output 'heatmaps.png'

unset key
set view map
set xtics border in scale 0,0 mirror norotate  offset character 0, 0, 0 autojustify
set ytics border in scale 0,0 mirror norotate  offset character 0, 0, 0 autojustify
set ztics border in scale 0,0 nomirror norotate  offset character 0, 0, 0 autojustify
set nocbtics
set rtics axis in scale 0,0 nomirror norotate  offset character 0, 0, 0 autojustify
set xrange [ -0.500000 : 4.50000 ] noreverse nowriteback
set yrange [ -0.500000 : 4.50000 ] noreverse nowriteback
set cbrange [ 0.00000 : 5.00000 ] noreverse nowriteback
set palette rgbformulae -7, 2, -7
splot 'heatmap.txt' matrix using 1:2:3 with image, \
      'heatmap.txt' matrix using 1:2:($3 == 0 ? " " : sprintf("$3") ) with labels

这个脚本只是在每个标签上打印出“3”。你可以帮帮我吗?感谢

并且还标记为Xtics和Ytics

 Tipe1 Tipe2 Tipe3 Tipe4 Tipe5
Failure1 6 2 0 0 1
Failure2 0 0 0 1 0
Failure3 0 0 0 2 3
Failure4 0 1 2 4 4
Failure5 1 2 3 4 6

再次感谢

1 个答案:

答案 0 :(得分:2)

我认为问题是对sprintf函数的错误调用。

sprintf(format,values)

您应该使用格式为%d)的十进制数字和要显示的标签值(第三列$3)调用sprintf:

sprintf("%d",$3) 

我将您的数据复制到一个文件(名为data)中,此示例效果很好:

plot 'data' matrix using 1:2:3 with image, '' matrix using 1:2:($3==0 ? " " : sprintf("%d",$3)) with labels  

希望它有所帮助!

相关问题