How to plot a vector (i.e. 1xN or Nx1 matrix) as image? I have no problem to plot 2x2 matrices, as follows:
plot '-' matrix with image
1 2
3 4
e
However, the following two examples with 2x1 and 1x2 matrices fail:
plot '-' matrix with image
1
3
e
plot '-' matrix with image
1 2
e
For both, I get the warning:
Image grid must be at least 4 points (2 x 2).
and nothing is rendered.
Is there another way to plot the Nx1 or 1xN matrices, so that they are rendered similar to the 2x2 matrix?
"gnuplot matrix or palette using one line" might be in parts related. However, the problem there is much more complex.
Here is a simple way which works also with 1xN
and Nx1
matrices.
It is using plotting style with boxxyerror
. It works for gnuplot 5.x and with files instead of datablocks probably also for gnuplot 4.x.
Script: (works for gnuplot>=5.0.0)
### plot small matrix
reset session
$Data1 <<EOD
1 2
3 4
EOD
$Data2 <<EOD
1
3
EOD
$Data3 <<EOD
1 2
EOD
set size ratio -1
set style fill solid 1.0
set key noautotitle
set cbrange[1:4]
set xtics 1
set ytics 1
set cbtics 1
set multiplot layout 1,3
plot $Data1 u 1:2:(0.5):(0.5):3 matrix w boxxy lc palette z
plot $Data2 u 1:2:(0.5):(0.5):3 matrix w boxxy lc palette z
plot $Data3 u 1:2:(0.5):(0.5):3 matrix w boxxy lc palette z
unset multiplot
### end of script
Result: