Reputation: 741
I am trying to generate a Heatmap with gnuplot but with a two distinct information for each entry in the heatmap. While heatmap shows the value as color, I want each block in the heatmap to show textual information as well.
The following script creates half of what I have in mind:
set term postscript eps color solid
set output '1.eps'
set title "Heat Map generated from a file containing Z values only"
unset key
set tic scale 0
set border linewidth 2
set palette rgbformula -7,2,-3
unset cbtics
unset colorbox
unset xtics
set x2tics ("A" 0, "B" 1, "C" 2, "D" 3, "E" 4)
set ytics ("N0" 0, "N1" 1, "N2" 2, "N3" 3, "N4" 4)
set style line 102 lc rgb'#101010' lt 0 lw 4
set grid front ls 102
set datafile separator ","
plot 'matrix.txt' matrix with image, "" matrix using 1:2:(sprintf('%.2f', $3)) with labels font ',12' offset 0,1.2
set datafile separator
The data file, matrix.txt contains the following information:
7 B, 5 B, 4 D, 3 B, 1 D
2 B, 2 A, 2 D, 0 C, 0 A
3 B, 0 A, 0 E, 0 E, 1 C
4 C, 0 A, 0 B, 0 E, 2 C
5 D, 0 A, 1 A, 2 A, 4 A
The following graph can be resulted from the script:
I want to be able to add the textual information in each entry as second part of the matrix entries (under the grid line).
I was wondering if you guys have any suggestions on how. Thanks
Upvotes: 2
Views: 1217
Reputation: 48390
Seems like you cannot use stringcolumn
(or strcol
) together with matrix
to get the complete string contained in the respective matrix elements. As workaround you must iterate over all columns and plot each of them separately with labels:
set title "Heat Map generated from a file containing Z values only"
unset key
set tic scale 0
set border linewidth 2
set palette rgbformula -7,2,-3
unset cbtics
unset colorbox
unset xtics
set x2tics ("A" 0, "B" 1, "C" 2, "D" 3, "E" 4)
set ytics ("N0" 0, "N1" 1, "N2" 2, "N3" 3, "N4" 4)
set style line 102 lc rgb'#101010' lt 0 lw 4
set grid front ls 102
set datafile separator ","
plot 'matrix.txt' matrix with image, \
for [i=1:5] '' using 0:(i-1):i with labels font ',12' offset 0,1.2
Upvotes: 2