gnuplot syntax

gnuplot

1 Label position

e.g. set label 1 'interaural time differences' at -15,0.85 front right at -15, 0.85 position coordinate, x=-15, y=0.85 position is specified by either x,y or x,y,z (coordinates), and may be preceded by first, second, graph, screen, or character to select the coordinate system. See 2 for details.

2 coordinates

coordinates in official web Syntax:

  • {<system>} <x>, {<system>} <y> {,{<system>} <z>}
    • system can either be first, second, graph, screen, or character.
  • places the x, y, or z coordinate in the system defined by the left and bottom axes

e.g. set key at first 2, 5

second
places it in the system defined by the second axes (top and right)
graph
specifies the area within the axes
  • 0,0 is bottom left and 1,1 is top right (for splot, 0,0,0 is bottom left of plotting area; use negative z to get to the base – see set ticslevel

e.g. set key at graph .5, .5 # set the key at the middle of the graph

3 Symbols

keywords: enhanced text mode

~U{0.8-} ## \( \overline{U} \)

U{/Symbol \245} #U

{/Symbol \245} #∞, infinity

{/Symbol q} # θ {/Symbol q}_R = 0^{0} θR=0\degree

Symbol and alphabet is as follows.

ALPHABET SYMBOL ALPHABET SYMBOL alphabet symbol alphabet symbol

A Alpha N Nu a alpha n nu B Beta O Omicron b beta o omicron C Chi P Pi c chi p pi D Delta Q Theta d delta q theta E Epsilon R Rho e epsilon r rho F Phi S Sigma f phi s sigma G Gamma T Tau g gamma t tau H Eta U Upsilon h eta u upsilon I iota W Omega i iota w omega K Kappa X Xi k kappa x xi L Lambda Y Psi l lambda y psi M Mu Z Zeta m mu z zeta

^ ax superscript  
_ ax subscript
@ @x or a@bc phantom box (occupies no width)
& &{space} inserts space of specified length
~ ~a{.8-} overprints '-' on 'a', raised by .8
     

http://materials.ucsd.edu/doc/ps_guide.pdf

Control Example Result Explanation

@ a@bcd ab

cd phantom box (occupies no width) & d&{space}b d b inserts space of specilized length ~ ~a{.8-} ~a overprints '-' on 'a', raised by .8 times the current fontsize {/Times abc} abc print abc in font Times at current size {/Times*2 abc} abc print abc in font Times at twice current size {/Times:Italic abc} abc print abc in font Times with style italic

4 key

 

4.1 key position

> set key out horiz center top ## key outside, horizontal, center ,top e.g. key_out_horiz_top.png

key out vertical centra right > set key right > set key outside right bottom vertical Right noreverse enhanced autotitles box linetype -1 linewidth 1.000 > set title "Key (out vert cent right)" http://gnuplot.sourceforge.net/demo_4.4/key.html

set key at graph .7, .9 top right,

4.2 gnuplot legend overlaps graph

key=legend

4.3 key

key=legend the set key command enables a key (or legend) containing a title and a sample (line, point, box) for each plot in the graph. set key top left

4.3.1 syntax

set key {on|off} {default} {{inside | outside} | {lmargin | rmargin | tmargin | bmargin}

{at <position>}}

{left | right | center} {top | bottom | center} {vertical | horizontal} {Left | Right} {{no}opaque} {{no}reverse} {{no}invert} {samplen <samplelength>} {spacing <verticalspacing>} {width <widthincrement>} {height <heightincrement>} {{no}autotitle {columnheader}} {title "<text>"} {{no}enhanced} {font "<face>,<size>"} {textcolor <colorspec>} {{no}box {linestyle <style> | linetype <type> | linewidth <width>}} {maxcols {<max no. of columns> | auto}} {maxrows {<max no. of rows> | auto}}

5 FAQ

 

5.1 Zooming in with multiplot

 

5.1.1 code

#!/usr/bin/gnuplot

reset

set terminal wxt size 350,262 enhanced font 'Verdana,10' persist

#set terminal pngcairo size 350,262 enhanced font 'Verdana,10' #set output 'zoomplot.png'

set style line 2 lc rgb '#0025ad' lt 1 lw 2 set style line 3 lc rgb '#0042ad' lt 1 lw 2 set style line 4 lc rgb '#0060ad' lt 1 lw 2 set style line 5 lc rgb '#007cad' lt 1 lw 2 set style line 6 lc rgb '#0099ad' lt 1 lw 2 set style line 7 lc rgb '#00ada4' lt 1 lw 2 set style line 8 lc rgb '#00ad88' lt 1 lw 2 set style line 9 lc rgb '#00ad6b' lt 1 lw 2 set style line 10 lc rgb '#00ad4e' lt 1 lw 2 set style line 11 lc rgb '#00ad31' lt 1 lw 2 set style line 12 lc rgb '#00ad14' lt 1 lw 2 set style line 13 lc rgb '#09ad00' lt 1 lw 2

unset key

set style line 101 lc rgb '#808080' lt 1 set border 3 back ls 101 set tics nomirror out scale 0.75

set style line 102 lc rgb'#808080' lt 0 lw 1 set grid back ls 102

set format x '%g°' set xlabel 'azimuth angle' set ylabel 'time / ms' offset 1,0

set xrange [-90:0] set yrange [0:0.9]

set label 1 'interaural time differences' at -15,0.85 front right set label 2 'f = 236Hz' at -28,0.45 textcolor ls 2 set label 3 'f = 1296Hz' at -12,0.05 right textcolor ls 13

set multiplot

set object 1 rect from -88,0.03 to -49,0.41 set object 1 rect fc rgb 'white' fillstyle solid 0.0 noborder plot for [n=2:13] 'itd.txt' u 1:(column(n)*1000) w lines ls n

do for [n=2:13] { set style line n lw 1 } set origin 0.12,0.17 set size 0.45,0.4 set xrange [-10:0] set yrange [0:0.1] unset xlabel unset ylabel unset label unset object 1 set tics scale 0.5 front set xtics 10 offset 0,0.5 set ytics 0.1 offset 0.5,0 plot for [n=2:13] 'itd.txt' u 1:(column(n)*1000) w lines ls n

unset multiplot

6 PLotting with error bar

plot "e387bem/eppexp.dat" t "luznik-exp" with errorbars ,\

"e387exp/Cpnowavee387luznik95CI.dat" with errorbars notitle,\ "e387exp/Cpnowavee387luznik95CI.dat" using 1:2 pt 2 t "Exp95%CI",\

https://stackoverflow.com/questions/10684182/gnuplot-with-errorbars-plotting

6.1 Data

syntax: (x, y, ydelta)

4.5 0.38 0.048 5.0 0.39 0.048 5.5 0.37 0.046 6.0 0.33 0.041 6.5 0.30 0.038 7.0 0.27 0.031 7.5 0.23 0.028 8.0 0.18 0.023 8.5 0.125 0.018

7 Plotting data with points

data file

# plotting_data1.dat
#  X Y
    1  2
    2  3

set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5 # — blue plot 'plottingdata1.dat' with linespoints ls 1

  • pt point type
  • ps point size

figures\alfa_epp_a7.eps

9 Introduction

command-line graphing It was originally created to allow scientists and students to visualize mathematical functions and data interactively

Command language is case sensitve,i.e. commands and function names written in lowercase are not the same as those written in capitals
commands in a line must be separated by semicolon(;)
Strings can be either single or double quotes
i.e.

/set title "my first plot"; plot 'data'; print "all done!"/

{} #optional choice
\| #separates mutually exclusive choice
<> #mark replaceable tokens

10 Comments

#, comment Comments are supported as follows: a # may appear in most places in a line and gnuplot will ignore the rest of the line.

It will not have this effect inside quotes, inside numbers (including complex numbers), inside command substitutions, etc. In short, it works anywhere it makes sense to work. See also set datafile commentschars (p. 109) for specifying comment characters in data files. Note that if a comment line ends in '\' then the subsequent line is also treated as a comment.

11 Terminal

 

11.1 postscript

set terminal postscript eps enhanced color font 'Helvetica,10' size 3in, 3in ~set output 'introduction.eps'~ Besides, the postscript terminal can’t handle all UTF-8 input characters and we have to use the enhanced mode to produce greek letter etc. But in opposite to the before mentioned terminals the enhanced mode will work fully for the postscript terminal.

set xlabel '{/Helvetica-Oblique x}' set ylabel '{/Helvetica-Oblique y}' set xtics ('-2{/Symbol p}' -2*pi,'-{/Symbol p}' -pi,0, \ '{/Symbol p}' pi,'2{/Symbol p}' 2*pi) plot f(x) title 'sin({/Helvetica-Oblique x})' with lines linestyle 1, \

11.1.1 syntax

set terminal postscript {default} set terminal postscript {landscape | portrait | eps} {enhanced | noenhanced} {defaultplex | simplex | duplex} {fontfile [add | delete] "<filename>"| nofontfiles} {{no}adobeglyphnames} {level1 | leveldefault | level3} {color | colour | monochrome} {background <rgbcolor> | nobackground} {dashlength | dl <DL>} {linewidth | lw <LW>} {rounded | butt} {clip | noclip} {palfuncparam <samples>{,<maxdeviation>}} {size <XX>{unit},<YY>{unit}} {blacktext | colortext | colourtext} {{font} "fontname{,fontsize}" {<fontsize>}} {fontscale <scale>}

11.2 pdf

 

11.2.1 test

gnuplot> set terminal pdf monochrome
gnuplot> set output "graph.pdf"
gnuplot> test
gnuplot> unset output
  • not recommended

set terminal pdf {monochrome|color|colour} {{no}enhanced} {fname "<font>"} {fsize <fontsize>} {font "<fontname>{,<fontsize>}"} {fontscale <scale>} {linewidth <lw>} {rounded|butt} {dl <dashlength>}} {size <XX>{unit},<YY>{unit}} The default is to use a different color for each line type. Selecting monochome will use black for all linetypes, Even in in mono mode you can still use explicit colors for filled areas or linestyles.

where <font> is the name of the default font to use (default Helvetica) and <fontsize> is the font size (in points, default 12). For help on which fonts are available or how to install new ones, please see the documentation for your local installation of pdflib.

The enhanced option enables enhanced text processing features (subscripts, superscripts and mixed fonts). See enhanced.

The width of all lines in the plot can be increased by the factor <n> specified in linewidth. Similarly dashlength is a multiplier for the default dash spacing.

rounded sets line caps and line joins to be rounded; butt is the default, butt caps and mitered joins.

The default size for PDF output is 5 inches by 3 inches. The size option changes this to whatever the user requests. By default the X and Y sizes are taken to be in inches, but other units are possible (currently only cm).

12 Syntax:

set terminal {<terminal-type> | push | pop} show terminal

If <terminal-type> is omitted, gnuplot will list the available terminal types. <terminal-type> may be abbreviated. If both set terminal and set output are used together, it is safest to give set terminal rst, because some terminals set a ag which is needed in some operating systems.

13 load scripts in Linux

script is suffix with script.gnu To load a script:

> load "sample.gnu"

14 gnuplot on Windows

 

14.1 change directory

~cd 'C:\Users\exw692\Documents\gnuplot'~

  • use single quote for directory

15 X11

gnuplot provides the x11 terminal type for use with X servers. This terminal type is set automatically at startup if the DISPLAY environment variable is set, if the TERM environment variable is set to xterm, or if the -display command line option is used. Syntax: set terminal x11 {<n>} {title "<string>"} {{no}enhanced} {font <fontspec>} {{no}persist} {{no}raise} {solid|dashed} {{no}ctrlq} {close} set terminal x11 {reset}

Autoscaling may be set individually on the x, y or z axis or globally on all axes. The default is to autoscale all axes. If you want to autoscale based on a subset of the plots in the figure, you can mark the other ones with the flag noautoscale. See data file (p. 78). Syntax: set autoscale {<axes>{|min|max|fixmin|fixmax|fix} | fix | keepfix} unset autoscale {<axes>} show autoscale where <axes> is either x, y, z, cb, x2, y2 or xy. A keyword with min or max appended (this cannot be done with xy) tells gnuplot to autoscale just the minimum or maximum of that axis. If no keyword is given, all axes are autoscaled.

Plotting plot generates 2D plots, splot generates 3D plots (actually 2D projections, of course

16 line types

the postscript terminal shows different dash patterns: type the following commands, and you will see the line types in an image named "test"

linestyle
user defined line style
linetype
system defined
set terminal postscript eps color colortext
set output 'test.eps'
test
set output

http://gnuplot.sourceforge.net/docs_4.2/node62.html

16.1 dashed line

  • depends on selectd terminal
  • png don't support dashed lines
  • pngcairo, support dashed lines, but it is disables by default. To enable it, use set termoption dashed, or set terminal pngcairo dashed ….
  • To see the defined linetype, use the test command:

++ set terminal pngcairo dashed set output 'test.png' test set output ++

16.2 line with points

set style line 1 linecolor rgb "red" linewidth 1.000 lt 1 pointtype 1 plot "e387bem/fort.101" using 1:2 t "TSR 1" ls 1 with linespoints

17 line style and arrow

 

17.1 Syntax:

set style line <index> default set style line <index> {{linetype | lt} <linetype> | <colorspec>} {{linecolor | lc} <colorspec>} {{linewidth | lw} <linewidth>} {{pointtype | pt} <pointtype>} {{pointsize | ps} <pointsize>} {{pointinterval | pi} <interval>} {{dashtype | dt} <dashtype>} {palette} unset style line show style line

17.2 example

set style line 1 lt 1 lc rgb "black" lw 1 lc line color lw line width http://gnuplot.sourceforge.net/demo_5.0/lines_arrows.html

18 Example

 

18.1 Eldad Avital

#set terminal jpeg #set output 'airfoile387bluntsharp.pdf' set terminal postscript eps enhanced color font 20 size 3in, 3in set out 'airfoile387bluntsharp.eps' #set terminal X11 set autoscale unset log unset label unset pm3d set key at graph .8, .9 set key spacing 1.2 set xtic auto set ytic auto set xlabel "x/R" set xrange [*:1]

set yrange [*:*] set ylabel "y/c set style line 1 lt 1 lc rgb "black" lw 1

set style line 2 lt 2 lc rgb "red" lw 4

set style line 3 lt 3 lc rgb "purple" lw 3 set style line 4 lt 4 lc rgb "blue" lw 3 set style line 5 lt 5 lc rgb "black" lw 2 set style line 6 lt 6 lc rgb "brown" lw 3 plot "2de287sharp.txt" using 1:2 t "E387 sharp" ls 1 with lines,\ "2de387bluntcoor.txt" using 1:2 t "E387 blunt" ls 2 with lines

18.2 Join data points with non-continuous lines

18.3 case 2

set terminal pngcairo size 350,262.5 enhanced font 'Verdana,10' set output 'terminalpng.png'

set border linewidth 1.5 set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2 # blue set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 2 # red

set key at 6.1,1.3

set xlabel 'x' set ylabel 'y'

set xrange[-2*pi:2*pi] set yrange[-1.5:1.5]

set xtics ("-2Ï€" -2*pi, "-Ï€" -pi, 0, "Ï€" pi, "2Ï€" 2*pi) set ytics 1 set tics scale 0.75

a = 0.9 f(x) = a * sin(x) g(x) = a * cos(x)

plot f(x) title 'sin(x)' with lines ls 1, \ g(x) notitle with lines ls 2

19 Output

By default, screens are displayed to the standard output. The set output command redirects the display to the specified file or device.

Syntax: set output {"<filename>"} show output The filename must be enclosed in quotes, e.g.

set output 'model.jpeg'

Plotting Functions Basic Plotting1

20 sine wave

sin wave plotting Radians is used for trigonometric functions xlabel:label for X axis For the Greek symbols the terminal's "enhanced" option must be used. This is done in the set terminal command. xtic: marker on the x-axis The xzeroaxis command draws a horizontal line along the zero value on the Y axis (parallel to the X axis). Example ~# Clear any previous plots. clear

reset

set key off

set title "Sine against Phase"

set xrange [0:6.28]

set xlabel "Phase (radians)"

set xtics ("0" 0,"0.5{/Symbol p}" pi/2, "{/Symbol p}" pi, \ "1.5{/Symbol p}" 1.5*pi, "2{/Symbol p}" 2*pi)

set xzeroaxis

set yrange [-1:1]

unset ytics

set terminal wxt enhanced

plot sin(x)~

21 Abbreviation

lt #line type lc #line color lw # line width

23 log

line type and point type not compatiable Warning: No pointtype specifier allowed, here

Footnotes:

1

https://www.cs.hmc.edu/~vrable/gnuplot/using-gnuplot.html

In gnuplot, exponentiation uses **, not ^.

From

Author: kemina

Created: 2019-03-20 Wed 09:42

Emacs 24.5.1 (Org mode 8.2.10)

Validate

posted @ 2019-03-20 09:45  kaiming_ai  阅读(496)  评论(0编辑  收藏  举报