I would like to create a heatmap with gnuplot based on a non-uniform grid, meaning that my x axis bins do not have all the same width, and I can\'t figure out how to do that
The easiest (maybe only viable) way is to add some dummy data points and use splot ... with pm3d
. This plotting style handles heatmaps with general quadrangles.
The image
plotting style plots one box (one big pixel) for each data point, while pm3d
takes each data point as corner of one or more quadrangles. The color of each quadrangles is determined by the values of the corners and is adjustable with set pm3d corners2color
.
So, in your case you need to expand the 4x4
matrix to a 5x5
matrix (expand to right and top), but select the lower left corner to determine the color set pm3d corners2color c1
.
The changed data file is then:
1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2
1 5 0.5
2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1
2 5 0.5
5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9
5 5 0.5
7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6
7 5 0.5
10 1 0.5
10 2 0.5
10 3 0.5
10 4 0.5
10 5 0.5
To plot it use
set pm3d map corners2color c1
set autoscale fix
set ytics 1
splot 'mydata.dat' using 1:($2-0.5):3 notitle
The result with 4.6.3 is:
In general, the z
-value of the dummy data points doesn't matter, but in the above script it should lay somewhere between minimum and maximum values to allow set autoscale fix
to work properly on the color scale.
If you don't want to change the data file manually, you could do it with some script, but that's a different question.