Select Page

Plotting Data in Gnuplot

(Back to index page)

Normally, you do not need to import the data into gnuplot to plot it.  
Just use the plot command directly with the filename

plot “filename.dat” with line using 1:2


plot = is the command to plot

“filename.dat” = is the filename and the filetype located in the active folder

with line = how will you plot your data? This command uses a line connecting the datapoints.
Another option is “with point”. There are various options that you can choose but you will need to learn/explore it. Please google yourself for more info.

using 1:2 = this command tells gnuplot which column in your “filename.dat” to plot your data.
In this case, it is columns 1 and 2 for x and y, respectively.

If this does not work, there are several possible reasons:

  1. The folder location is wrong
  2. The filename is wrong
  3. The selected columns are wrong
  4. The datafile separator is different
  5. and other reasons that I do not know yet..

(Back to index page)

You can also perform mathematical operations on the data directly.  For example, you want to squareroot column 2 in the data… or maybe multiply it with 1000.. or sine it.. you get the idea.

To do this, use parentheses ( ) and you can perform such operations.. For example:

using ($1):2 = the dollar sign indicates column. If you do not put $ symbol, the “1” will be the number 1 and not a constant. As you can see, there is no mathematical operation here (yet).

using ($1*2):2 = multiplies column 1 with 2.

using ($1**4):2 = column 1 to the power of 4.

using 1:(sqrt($2**2+$3**2)) = square root the sum of squared data from column 2 and 3.

You can perform all sorts of maths operation to the data..

(Back to index page)