Cheat Logo

Cheat Sheet

Reading data from a file

Level: Intermediate
OS:
  • OS X
  • Linux
  • BSD
  • Solaris
Programs:
  • Gnuplot

I usually use gnuplot to plot data from a file, typically stored as a csv or tsv spreadsheet. gnuplot needs to be told which format to use:

  • set datafile separator "," for comma separated
  • set datafile separator "\t" for tab separated

For each plot command, you must tell gnuplot which data file to use. For example, to plot columns 5 and 6 vs column 1 in 'foo.csv' and column 2 vs 1 in 'bar.csv':

set datafile separator ","
plot 'foo.csv' using 1:5,\
     'foo.csv' using 1:6,\
     'bar.csv' using 1:2

If you are plotting multiple columns of data and some odd values are showing up, it may be due to missing data. In some cases you need to manually tell gnuplot what to do with missing data. For example, if missing points are simply left blank, use the command:

set datafile missing ""
©2015 Schutt Design (Luke & Noel Schutt).
Contact us using one of our first names at schuttdesign dot net.