Tuesday, July 12, 2011

Joining string variables

When defining file names or titles, is often useful to join string variables in order to make our scripts more comprehensible. To do so, you have to join this variables using dots.
Example:
  • DATA='satellite'
  • DATE='12/07/12'
  • EXTENSION='dat'
  • set title DATA.' measurements - '.DATE
  • plot DATA.'_data.'.EXTENSION
This will plot the file "satellite_data.dat" and will entitle the plot as "satellite measurements - 12/07/12"

Monday, July 11, 2011

Rotating axes labels

The command to rotate the labels in one of the axis is:
  • set <axis>tic rotate by <angle> scale <size>
The parameter scale must be a number and accounts for the size of the tics in the selected axis.
Example:
  • set xtic rotate by 90 scale 0.5
Caution: Be careful when rotating an angle non multiple of 90 because it can lead to non desired effects.

Wednesday, July 6, 2011

Conditional statements

The syntaxis for writing conditional statements in GNUPLOT is:
  • if (<condition>) <command1>; <command2>; ...; else <command1>; <command2>; ...

List of conditions:
  eq  equal to (for strings)
  ne  non equal to (for strings)
  ==  equal to (for numbers)
  !=  non equal to (for numbers)
  <   lower than
  <=  lower than or equal to
  >   greater than
  >=  greater than or equal to

Combining several conditions:
  &&  and
  ||  or

Example:
  • if (FILE_NUM==1) \
  • 'whatever1.dat' u 1:2 w l lw 1 lt 3 notitle;\
  • 'whatever1.dat' u 1:3 w l lw 5 lt 1 notitle
  • if (FILE_NUM==2) \
  • 'whatever2.dat' u 1:2 w l lw 1 lt 3 notitle;\
  • 'whatever2.dat' u 1:3 w l lw 5 lt 1 notitle

Tuesday, July 5, 2011

Working with the columns of the data file

This post talks about how to control the information about the columns in a data file.

1) Once we want to plot the data contained in a data file, we can just write:
  • plot 'whatever.dat'
This will take the first column of the data file as the X coordinate and the second column as the Y coordinate.

2) In order to specify which column corresponds to each coordinate, we can write, for instance:
  • plot 'whatever.dat' u 3:2
It will take the data in the third column as the X coordinate and the data in the second column as the Y coordinate.

3) We can also treat any of the columns as a variable (previously defined):
  • COL=2
  • plot 'whatever.dat' u 3:COL

4) In order to perform mathematic operations to the number of any column, we must use parentheses:
  • COL=3
  • plot 'whatever.dat' u COL:(COL-1)

5) Nevertheless, if we want to operate the values contained in the column (not the number of the column), we have to use the dollar sign:
  • plot 'whatever.dat' u (cos($3)):5

6) Finally, if we want to perform the mathematic operation to the value of a column specified with a variable, we will have to use the function column:
  • COL=3
  • plot 'whatever.dat' u (cos(column(COL))):5