Professor Pai H. Chou

Gnuplot cheat-sheet

This cheat-sheet is for plotting data files (rather than equations). A lot of the content is extracted from the Introduction to Gnuplot by Bob Dowling at University of Cambridge.

Output format and device

Set the terminal:

  • set terminal [pdf|png|aqua] (for PDF file output, PNG file, or AquaTerminal on Mac OS X)

Setting the file name

  • set output "myplot.pdf" (replace myplot with your file name)

Plotting

  • plot "mydata.dat" (the data file extension doesn’t matter)
  • plot "mydata.dat" using 3 title "my3rdseries" (data from the 3rd column vs. 1, 2, 3, 4, …) with the title my3rdseries in the legend
  • plot "mydata.data" using X:Y (X and Y are column numbers to select)

Display

To set the plot size and aspect ratio

  • picsize X Y (replace X Y with your pixel counts)
  • set size ratio R (replace R with your own, for the graph)
  • set size ratio -R (replace -R with your own, for the units)

As marks (diff. symbol for each series), lines, or just simple dots

  • set style data [points|lines|dots] (points can be some marks but dots are just dots; lines connect)

Range

  • set xrange [L:U] (L for lower bound, U for upper bound)
  • set yrange [L:U] (use * for default)

Axes

Tick interval

  • set xticks N (replace N with your own number for major ticks)
  • set yticks N
  • set mxticks M (M for minor ticks - i.e., marked but no number)

Showing the Axes

  • set zeroaxis (shows both X and Y axes)
  • set xzeroaxis (show X axis)
  • set yzeroaxis (show Y axis)

Legend

Placing the legend (“key”)

  • set key [top|bottom] [left|right]
  • unset key

Title for a data series in the legend

  • plot "mydata" title "mytitle" (replace mydata and mytitle with your own file name and the text title to use for that data series)
  • plot "mydata" notitle

File format

Using alternative separators

  • set datafile separator "," (for comma-separated file, CSV)