Question

Base on gnuplot example about "Heat map with non-zero pixel values written as labels" in here: http://gnuplot.sourceforge.net/demo_cvs/heatmaps.html

I have data:

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

and my 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

this script just printout "3" in every labels. Could you help me? thanks

and also label for Xtics and 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

Thanks again

Était-ce utile?

La solution

I think the problem is the wrong call to the sprintf function.

sprintf(format,values)

You should call sprintf with a decimal number in format (%d) and the label value you want to display (third column $3) :

sprintf("%d",$3) 

I copied your data into a file (named data) and this example works well :

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

Hope it helps!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top