Credits Overview Plotting Styles Commands Terminals

sparse matrix

Syntax:

      sparse matrix=(cols,rows) origin=(x0,y0) dx=<delx> dy=<dely>

The sparse matrix variant defines a uniform grid as part of the plot or splot command line. The grid is initially empty. Any number of individual points are then read from the input file, one per line, and assigned to the nearest grid point. I.e. a data line

      x y value

is evaluated as

      i = (x - x0) / delx
      j = (y - y0) / dely
      matrix[i,j] = value

The size of the matrix is required. origin (optional) defaults to origin=(0,0). dx (optional) defaults to dx=1. dy (optional) defaults to dy=dx.

The intended use of this variant is to generate heatmaps from unordered, possibly incomplete, data using the image, rgbimage, or rgbalpha plot styles. The example below generates a distance matrix in the form of a 4x4 heatmap with only the upper triangle elements present:

figure_sparsematrix

      $DATA << EOD
      1 1 10
      1 2 20
      1 3 30
      1 4 40
      2 2 10
      2 3 50
      2 4 60
      3 3 10
      3 4 20
      4 4 10
      EOD
      plot $DATA sparse matrix=(4,4) origin=(1,1) with image