11

How can I plot (a 2D plot) a matrix in Gnuplot having such data structure, using the first row and column as a x and y ticks (the first number of the first row is the number of columns) and represent the rest of the values by a colour mapping so it can be seen on a 2D plane ?

4 0.5 0.6 0.7 0.8
1 -6.20 -6.35 -6.59 -6.02
2 -6.39 -6.52 -6.31 -6.00
3 -6.36 -6.48 -6.15 -5.90
4 -5.79 -5.91 -5.87 -5.46
Jack
  • 725
  • 1
  • 10
  • 27

1 Answers1

15

You can plot this data format using matrix nonuniform.

To get a heatmap you can plot either with image (regular grid, no interpolation, one quadrangle for each data point), or splot with pm3d (supports also irregular grids and interpolation, plots one quadrangle for four neighboring data points.

  1. with image

    set autoscale xfix
    set autoscale yfix
    set autoscale cbfix
    plot 'data.dat' matrix nonuniform with image notitle
    

enter image description here

  1. pm3d

    set autoscale xfix
    set autoscale yfix
    set autoscale cbfix
    set pm3d map
    splot 'data.dat' matrix nonuniform notitle
    

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Thansk it worked. I have tried to do it with splot 'data.txt' with matrix , and it was giving me the number of columns and rows as indices. – Jack Sep 08 '15 at 13:39
  • No, "with matrix" simply is wrong syntax, "with" expects a plotting style. The trick for you data format is `matrix nonuniform`. – Christoph Sep 08 '15 at 13:54
  • How can we include the data in the heatmap - each value of the data to be inserted in it's corresponding `(x,y)` position on the grid? – Gathide Jan 16 '17 at 04:53
  • 1
    @Gathide Use the `labels` plotting style for this, see e.g. http://stackoverflow.com/a/27049991/2604213 – Christoph Jan 16 '17 at 07:34
  • 1
    In such plot , always there are square of different colors. Can I get this same plot with points (circular points) of different colors ? – Bapi Aug 23 '20 at 15:41