| Home |

Library -- Gnuplot Examples


I have updated this page on 2007/03/11. Old page is here, and another page in Japanese is here.
(I also recommend Kawano-san's page.)
  1. Let's get started...
  2. gnuplot-4.0
  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.
    $ gnuplot
    G N U P L O T
    Version 4.0 patchlevel 0
    ....
    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.0 patchlevel 0
    ....
    Terminal type set to 'x11'
    gnuplot> plot sin(x)
    gnuplot> quit
    $
    

  2. The current public version of gnuplot is Gnuplot-4.0. 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.0. 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.0
    lt1 2 3 4 5 6 7 8 9 lt>10
    colorred green blue magenta lightblueyellow black orangegrey color @ mod(lt-1,9)+1
    dashed type solid dashed short dashed dotted dot dashed dot short dashed ... ... ... dash @ mod(lt-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.0 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.0 script
    	

  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.


  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.


  5. For special characters in postscript, please search for it in the "docs/psdocs/ps_guide.ps" in the gnuplot package.
  6. I have two complains on the default version of gnuplot. One is that the dash length is too short (improved in gnuplot 4.0), and the second is that with "hist", gnuplot set both of the end points to zero, which is not always true especially in log plot. Then I usually use the following unofficial patch (for gnuplot 3.7.1) to make it my favorite.


| Home |


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