GNU sets the limits of the heatmap axis around a dynamically calculated point
I am drawing a heatmap in gnuplot from a text file which is in matrix format:
z11 z12 z13
z21 z22 z23
z31 z32 z33
and so on using the following command (disregarding the axis labels, etc.):
plot '~/some_text_file.txt' matrix notitle with image
The matrix is ββquite large, more than 50,000 elements in most cases, and it mostly has to do with the size of my y-dimension (#rows). I would like to know if there is a way to change the limits in y-dimension for a given number of values ββaround the maximum, while keeping the x and z dimensions the same. For example. if the maximum in the matrix is ββat [4000, 33], I want my y range to be centered at 4000 + - let's say 20% of the length of the y dimension.
Thank.
source to share
Edit:
The solution below is mostly the correct idea, however it works in my example, but not in general, because the error is in the way gnuplot uses the command stats
with matrix files. See the comments after the answer for more information.
You can do this by using stats
to dynamically display the indices corresponding to the maximum value.
Consider the following file, which I named data
:
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 5 3 4
0 1 2 3 4
If I run stats
I get:
gnuplot> stats "data" matrix
* FILE:
Records: 25
Out of range: 0
Invalid: 0
Blank: 0
Data Blocks: 1
* MATRIX: [5 X 5]
Mean: 2.1200
Std Dev: 1.5315
Sum: 53.0000
Sum Sq.: 171.0000
Minimum: 0.0000 [ 0 0 ]
Maximum: 5.0000 [ 3 2 ]
COG: 2.9434 2.0566
The maximum value is at the position [ 3 2 ]
meaning row 3 + 1 and column 2 + 1 (in gnuplot, the first row / column will be number 0). After startup, stats
some variables are created automatically ( help stats
for more information), among them STATS_index_max_x
and STATS_index_max_y
, which save the position of the maximum:
gnuplot> print STATS_index_max_x
3.0
gnuplot> print STATS_index_max_y
2.0
Which you can use to auto-dial ranges. Now, since it STATS_index_max_x
actually gives you the y position (instead of x), you need to be careful. The total number of rows to get the range can be obtained with a system call (maybe a better built-in function that I don't know about):
gnuplot> range = system("awk 'END{print NR}' data")
gnuplot> print range
5
So, basically you will be doing:
stats "data" matrix
range = system("awk 'END{print NR}' data")
range_center = STATS_index_max_x
d = 0.2 * range
set yrange [range_center - d : range_center + d]
which will center yrange
on the position of your maximum value and stretch it + 20% of its full range.
The result is plot "data" matrix w image
now
instead
source to share