Plotting with Gnuplot

by Robert L.E. BILLON

Last update
2010-11-04

Foreword   

Gnuplot is a marvelous plotting tool. It can plot curves in the plane or in 3D projection, This, in command line mode or from a script file. It can also plot curves from data files provided by data acquisition systems. Simple to use and efficient it will satisfy many scientific, professionnal or education oriented users. Gnuplot runs under Linux, but also under BeOS and some other systems. Its current version is 4.0 .

Préface   

Gnuplot est un outil merveilleux de tracé de courbes. Il peut tracer des courbes planes ainsi qu'en 3D, ceci en ligne de commande, à ou à partir d'un fichier de commandes. Il peut aussi tracer à partir d'un fichier de données provenant d'une centrale d'acquisition. Simple à utiliser et performant il peut satisfaire de nombreux utilisateurs scientifiques, professionnels ou encore dans l'enseignement. Gnuplot tourne sous Linux, mais aussi sous BeOS et quelques autres OS. Il est actuellement disponible dans sa version 4.0 .

How to get Gnuplot

Gnuplot comes now with most of the Linux distributions. It may be also downloaded from :

ftp:// ftp.gnuplot.org/pub/gnuplot/
ftp:// ftp.darmouth.edu/pub/gnuplot/

Comment obtenir Gnuplot

Gnuplot est maintenant inclus dans la plupart des distributions Linux. Il peut aussi être téléchargé, pour l'Europe, depuis :

ftp:// ftp.irisa.fr/pub/gnuplot/
ftp:// ftp.ucc.ie/pub/gnuplot/

Runing Gnuplot

Interactive mode :

Enter the command gnuplot , you get the prompt gnuplot>
Enter then the command plot sin(x) . Gnuplot open his own terminal and display the sin x curve. Hard to think more simple !


Running a script file :

Let us admit you created a script file named test.gp . At the prompt, enter load "test.gp" . Gnuplot executes the commands in the file test.gp and plots the corresponding curve.


Command line mode :

At the Linux prompt simply enter gnuplot test.gp

Taking coordinates from a datafile :

If your datafile is named test.dat, put on a line in your script the command plot "test.dat" . Your data will be automatically loaded by test.gp . The datafile admits one pair of x y coordinates on each line, separated by a space. If the interval between two points must not be plotted, then a blank line is introduced between these two pairs of coordinates. Lines begining par # are comments. An example hereafter.


#test datafile
108 87
108 82
104 72
88  57
#blank

93  75
93  78
91  82
...

Lancement de Gnuplot

Mode interactif :

Entrez la commande gnuplot , vous obtenez le prompt gnuplot>
Entrez alors la commande plot sin(x) . Gnuplot ouvre son propre terminal et affiche aussitôt la courbe de sinus x . Difficile d'imaginer plus simple !

Exécuter un fichier de commandes :

Admettons que vous avez créé un fichier de commandes que vous avez nommé test.gp . Au prompt, entrez la commande load "test.gp" . Gnuplot exécute le fichier test.gp et affiche le tracé correspondant.

Mode ligne de commande :

Au prompt de Linux entrez simplement la commande gnuplot test.gp

Puiser les coordonnées dans un fichier de donnés :

Si votre fichier de données s'appelle test.dat, mettez dans votre fichier de commandes une ligne avec plot "test.dat" . Les données seront automatiquement chargées par test.gp . Le fichier de données comporte une paire de coordonnées x y par ligne, séparées par un espace. Si l'intervalle entre deux points ne doit pas être plotté, une ligne blanche est introduite entre ces deux paires de coordonnées. Les lignes commençant par # sont des commentaires. Un exemple ci-dessous.

#fichier test
108 87
108 82
104 72
88  57
#une ligne vide

93  75
93  78
91  82
...

How to customize your Gnuplot terminal

Gnuplot provides usually a terminal with a white background, so some plottings may lack contrast. If you prefer a black background, add at the end of your ~/.Xdefaults script, the following lines.

# xterm config for gnuplot
gnuplot*background: black
gnuplot*textColor: white
gnuplot*axisColor: white
gnuplot*axisDashes: 22

Comment personaliser votre terminal Gnuplot

Gnuplot procure habituellement un terminal avec fond blanc, ainsi certains tracés peuvent manquer de contraste. Si vous préférez un fond noir, ajoutez à la fin de votre ~/.Xdefaults , les lignes suivantes.

# xterm config for gnuplot
gnuplot*background: black
gnuplot*textColor: white
gnuplot*axisColor: white
gnuplot*axisDashes: 22

Online help

Gnuplot comes with a very clear and complete help text. To put you into the help file, simply enter the help command. Many topics and subtopics are included.

Aide en ligne

Gnuplot inclus un texte d'aide très clair et très complet. Pour l'obtenir, entrer simplement help . Il comporte de nombreuses rubriques et sous-rubriques.

Screen snapshots

Curves in the plane
3D plots
Plotting from a datafile
Header template





Demo files

gp_ballistic.gp
gp_curves.gp
gp_electr.gp
gp_girl.dat
gp_girl.gp
gp_show.dem
gp_surfaces.gp
gp_volumes.gp
gp_theend.gp

Copies d'écran

Courbes dans le plan
Tracé de volumes
Tracé avec fichier de données
Modèle d'en-tête





Fichiers de démo

gp_ballistic.gp
gp_curves.gp
gp_electr.gp
gp_girl.dat
gp_girl.gp
gp_show.dem
gp_surfaces.gp
gp_volumes.gp
gp_theend.gp

Gnuplot on the web

 The following sites have more information about gnuplot.


    
File: gnuplot.html - Robert L.E. Billon, 2001-11-19 - Last update: 2010-11-04