| Home |

Library -- Gnuplot Examples



  1. Let's get started...
  2. gnuplot-4.2
  3. Print it out to PS printer
  4. Examples

I love Gnuplot.

  1. To get started, just type
    gnuplot [script-filename]
    Or if you are a beginner, after going into gnuplot (without filename), type
    help plot
    then you will see some explanations.
    
    	G N U P L O T
    	Version 4.2 patchlevel 3 
    	last modified Mar 2008
    	System: Linux 2.6.27-14-generic
    
    	Copyright (C) 1986 - 1993, 1998, 2004, 2007, 2008
    	Thomas Williams, Colin Kelley and many others
    
    	Type `help` to access the on-line reference manual.
    	The gnuplot FAQ is available from http://www.gnuplot.info/faq/
    
    	Send bug reports and suggestions to <http://sourceforge.net/projects/gnuplot>
    
    
    Terminal type set to 'x11'
    gnuplot> help plot
    `plot` is the primary command for drawing plots with `gnuplot`. ...
    
    Syntax:
          plot {}
               { | {"" {datafile-modifiers}}}
               ...
    gnuplot> quit
    $
    
    
    One of the simplest sample is the following.
    $ gnuplot
    G N U P L O T
    Version 4.2 patchlevel 3
    ....
    Terminal type set to 'x11'
    gnuplot> plot sin(x)
    gnuplot> quit
    $
    

  2. The current public version of gnuplot is Gnuplot-4.2. It supports greek letters, super- and sub-scripts in postscript output. (See "help postscript" for detail.)

    The figure below is a sample output of gnuplot4.2. The horizontal axis is the type of points, and the vertical axis is the type of lines. (They are not K+ momentum etc.!!) The script file is here, and its output EPS file is here.

    Line and point color is specified by the linetype.
    linetype(lt)-color and lt-dash correspondence in gnuplot 4.2
    lt(or lc)1 2 3 4 5 6 7 8 9 lt(lc)>10
    dashed type
    (lt)
    solid dashed short dashed dotted dot dashed dot short dashed ... dot dot dashed ... dash @ mod(lt-1,9)+1
    color
    (lc)
    red green blue magenta lightblueyellow black orangegrey color @ mod(lc-1,9)+1

    The script file of color PS output is here, and its PS (eps) output is here.

    The above number-color correspondence in gnuplot-4.2 is the same in gnuplot-3.7. But the "linestyle" in 3.7 has to be replaced with "style line".

    set linestyle  1 lt 1 lw 6 # in gnuplot 3.7 script
    set style line 1 lt 1 lw 6 # in gnuplot 4.x script
    	

    [New in 4.2] In gnuplot-4.2, we can specify lt (line type) and lc (line color) separately. Now we can draw red-dashed (lt=2, lc=1) or black-solid (lt=1, lc=7) lines.

    set linestyle  1 lt 1 lc 7 # black-solid
    set linestyle  2 lt 2 lc 1 # red-dashed
    	

  3. In order to print out, you can type in gnuplot or write the following two lines in the script file.
    set term postscript
    set output "YOUR-OUTPUT-FILE-NAME"
    	
    and plot the figure. Then the figure is saved in the PS file which you specified.
    Interactive Session Example Script Session Example
    $ gnuplot
    gnuplot> set term postscript
    gnuplot> set output "YOUR-OUTPUT-FILE-NAME"
    gnuplot> plot ...
    gnuplot> quit
    $ lpr YOUR-OUTPUT-FILE-NAME
    
    $ gnuplot sin.plt
    $ lpr sin.ps
    
    with a test gnuplot script (sin.plt) as,
    set term postscript eps color enh "Times-BoldItalic"
    set title "sin(x)"
    set output "sin.ps"
    plot sin(x)
    

    You can put Greek and other character or symbols in postscript. Guide is here (ps) or here (pdf).


  4. Now, I have some EXAMPLES. The first one is 3-d plot, and the second one is a naive way of plot multi-figures in one plot.


| Home |


Akira Ohnishi <ohnishi_at_yukawa.kyoto-u.ac.jp>