On using gnuplot


I use {gnuplot} because:

General usage

The fastest way to plot from a file:

gnuplot '<file>' using 1:2 with lines title 'data'

Gnuplot can be scripted. The standard extension is .gp. Plot from a script:

gnuplot <script>.gp

Calling from C

Define GNUPLOT as

#define GNUPLOT "gnuplot -persist"

Plot with gnuplot as

FILE *fp;
      fp = popen(GNUPLOT, "w");
      fprintf(fp, "plot '-' w p lt -1 pt 6 title 'e and z'\n");

      for (int i = 0; i < N * (ngp + 2); i ++)
      fprintf(fp, "%f %f\n", x[i], e[i]);
      fprintf(fp, "\033");



Delimiters and comments

Specify the delimiter character:

set datafile separator "<char>"

Specify comment character:

set datafile commentschar "<char>"


The terminal determines how the plot is displayed. I like the terminals dumb, qt, and png. Specify the terminal:

set term dumb # plots to shell
      set term qt   # graphical output
      set term png  # plot to image file


The font can be specified through the term. For example

set term qt font "Times, 12"


set term pngcairo font "monospace"


Allows to plot several graphs in one figure, in a vertically or horizontally stacked way:

set multiplot layout 2,1 rowsfirst

      set title 'surface flow'
      plot '1.0e-06/surface_outlet_flux.dat' u 1:2 w l title 'i = 1.0e-06 m/s'

      set title 'subsurface flow'
      plot '1.0e-06/subsurface_outlet_flux.dat' u 1:2 w l title 'i = 1.0e-06 m/s'

      unset multiplot


Use this for plotting three-dimensional data:

splot "<file>" u 1:2:3 w l


Last updated: Wed Oct 13 09:54:00 2021