Richards Center at Yale University
RC Home | Search | Table of Contents | General Information

Last Modified: Friday, 27-Mar-2009 09:48:19 EDT


gnuplot is a command-driven interactive function and data plotting program. It can produce a large variety of plots and graphs interactively or in batch mode. It does not have a simple GUI interface, so it is not trivial to get started.

Documentation is at
Examples are at

Using gnuplot to produce a pseudo-color or grayscale image of a grid or matrix.

Example 1

The picture on the right was generated by a data file with 240 rows of 240 points each. It can be generated by the following commands.
      (1) > gnuplot
      (2) gnuplot> set xrange [0:239]; set yrange [0:239] 
      (3) gnuplot> set size ratio 1
      (4) gnuplot> set cbrange [0:100]
      (5) gnuplot> set pm3d map
      (6) gnuplot> set title "Figure 1"
      (7) gnuplot> splot 'n3.dat' matrix
  1. Invoke gnuplot
  2. Data points in x- and y- direction. Two commands separated by a semicolon.
  3. Ratio of y- to x- dimension.
  4. Values in the data file range from 0 to 100 in value.
  5. The kind of plot to draw
  6. Obvious
  7. Get data from file 'n3.dat'. Data are in form of a matrix.
If you now want to see the same plot in grayscale, type:
      gnuplot> set palette gray
      gnuplot> replot
If you want to switch back to the default colorscale:
      gnuplot> set palette rgbformulae 7,5,15
      gnuplot> replot

Example 2

This example shows:
  • Batch processing
  • Non-square matrix
  • Data file format
  • Saving plot as a file
The plot file "Figure2.gif" was generated from n15x20.cmd with the command gnuplot < n15x20.cmd. The following is a listing of n15x20.cmd:
    set xrange [0:14]; set yrange [0:19] 
    set size ratio 1.333
    set cbrange [0:100]
    set pm3d map
    set palette gray
    set title "Figure 2"
    set output 'Figure2.gif'
    set terminal gif
    splot 'n15x20.txt' matrix	      
The data file consists of 20 lines, each containing 15 numbers. To see the actual file in a new window, click here.

The line set size ratio 1.333 Says that the y-axis should be displayed 1.333 times the length of the x-axis. Otherwise gnuplot will use an inappropriate default and the grid points will not be square.

Note that even though the data matrix is 15x20, gnuplot scales the actual picture up or down to what it thinks is a reasonable size for viewing. In this case, each point in the matrix is displayed in a 20-pixel-square box.

Last Modified: Friday, 27-Mar-2009 09:48:19 EDT

RC Home | Search | Table of Contents | General Information
Richards Center ( at Yale University (
Contact: michael^strickler_at_yale^edu