Select Page

Importing Data into Gnuplot

(Back to index page)

To import data into Gnuplot, these are several guidelines that might be useful

  1. Understand your data
  2. Setting the current active folder location
  3. If necessary, recheck the current folder
  4. If necessary, change your datafile separator

Understanding your data

It is important that you understand your data. Things that you must be aware:

  1. File name, type and location of the file
  2. The contents of the file..
    what is used to separate the columns.. e.g. “tab” or “space” or “comma” or “semicolon”
    how many columns are there? and which column is important?
  3. Check the file if there are lines that is not suitable for plotting. e.g. a line of words.
    Place “#” in front of that line to make it into a comment and gnuplot will ignore that line.

Change the folder location

  1. Launch Gnuplot and change the active folder location to where your file is using:
    gnuplot > cd ‘c:\windows\user\desktop’
  2. If you wish, you can reconfirm the location using the command:
    gnuplot > pwd

Set/Verify the column separator

  1. By default, the column separator between data for gnuplot is whitespaces.
    “tab” and “spaces” are considered as whitespaces.
  2. You can change the data column separator using:
    gnuplot > set datafile separator ‘,’    <<< this changes it to comma
  3. You can check the data column seperator using:
    gnuplot > show datafile separator

Here is an example of different datafile separators:

# Data separated by comma

# Data separated by ;

# Data separated by whitespaces (e.g. spacebar)
123 123
234 234
345 345
456 567
456 567

# Data separated by whitespaces (e.g. tab)
123 123
234 234
345 345
456 567
456 567

Until here, you have only prepared to read the data file. 

(Back to index page)