With the data set just below, I want to change the xtics displayed
$data << EOD
xxx -2 -1 0 1 2
0 4 5 6 -3 -1
1 3 4 7 -4 -2
2 2 3 6 6 4
3 4 -3 -6 4 1
EOD
With the simple command plot $data matrix columnheaders rowheaders with image
, I got the image :
Now, if I add one xtick with set xtics add ("T" 0.577)
, I got the T label, but not at the right place (I would have expected to be between 0 & 1) as shown below :
Then, I do not manage to have only the T label without the other xtics, I tried the following sequence :
unset xtics
set xtics ("T" 0.577)
replot
I still get all the xtics as defined in the original dataset.
Let me try to explain. If you plotted the matrix
x A B C
K 1 2 3
L 4 5 6
M 7 8 9
the xtic labels would be A
, B
, C
, since gnuplot takes the columnheaders and rowheaders as text, not as numbers.
So, if you plot a MxN
matrix with image
, the x- and y-coordinates will actually be from 0
to M-1
and from 0
to N-1
, respectively. In your case, although, the xtic labels show -2
to 2
(i.e. these are just text labels) the x-range is actually from 0
to 4
.
Hence, as a solution you could interpolate your desired value in the range 0
to N-1
.
Maybe there are other possibilties, e.g. with splot
and pm3d
, but this would depend on your exact requirements.
In the example below stats
(check help stats
) is used to find the minimum and maxium x-coordinate and the number of columns of your matrix. You will get a warning warning: matrix contains missing or undefined values
, because you have xxx
as non-numerical value in your matrix. You can either ignore the warning or avoid the warning by replacing xxx
, e.g. by 0
.
Script:
### add special xtic on matrix with image
reset session
$Data << EOD
xxx -2 -1 0 1 2
0 4 5 6 -3 -1
1 3 4 7 -4 -2
2 2 3 6 6 4
3 4 -3 -6 4 1
EOD
stats $Data matrix every ::1:0::0 u 3 nooutput
x0 = STATS_min
x1 = STATS_max
N = STATS_columns-1
interpolate(x) = (x-x0)/(x1-x0)*N
set xtics out
set xtics add ("T" interpolate(0.577))
set xrange noextend
plot $Data matrix columnheaders rowheaders w image
### end of script
Result: