3
votes

As written in the manual of Gnuplot at page 136,

Because the pm3d algorithm does not extend the colored surface outside the range of the input data points, the 'c' coloring options will result in pixels along two edges of the grid not contributing to the color of any quadrangle. For example, applying the pm3d algorithm to the 4x4 grid of data points in script demo/pm3d.dem (please have a look) produces only (4-1)x(4-1)=9 colored rectangles.

So if I would like to plot a 4x4 pixel sized image, I can't do it in this way without missing the 4th column and row. (I would like not to modify the file.) Is there an efficent workaround for this problem?

1
Do you really need pm3d, i.e. do you need some kind of interpolation, or is a plot ... with image what you actually want? For this, see my (lenghty) answer to gnuplot matrix or palette using one line - Christoph
The plot ... with image satisfies my requirements. If you would write an answer I could accept it. This question is important and not trivial to use this solution because as I see it is an improvement in gnuplot since 4.3 - DanielTuzes

1 Answers

4
votes

To plot a 4x4 image which shows exactly the color rectangles specified in the data file, the splot ... with pm3d is not suited. For this one can use the image plotting style. The pm3d mode must be used e.g when the grid points are not equidistant, or for a 3D representation.

Taking the following file data.dat

1 6 8 3
2 5 4 4
9 1 1 2
5 4 3 8

a more or less minimal script would be

set autoscale fix
set xtics 1 out
set ytics 1 out
plot 'data.dat' matrix with image t ''

The result for set terminal pngcairo is:

enter image description here

The terminal must support plotting with image, this is the case for the most, but not for all (e.g. pstricks does not). In that case one would need to use with image failsafe.