% latex generated by the script '/home/project-web/bumble/cgi-bin/text2latex.cgi' % with help from the sed script 'text2latex.sed' % query string: 'books/gnuplot/gnuplot-book' % sFileName= 'gnuplot-book' % sDirName = 'books/gnuplot' % sName = '' --> % latex by http://bumble.sourceforge.net/scripts/text2latex.sed % this script is a work in progress \documentclass[11pt]{article} \usepackage[hmargin=2cm, vmargin=2cm]{geometry} \usepackage{url} \usepackage{hyperref} \begin{document} \\&\\& The Gnuplot Graphing program -------------------------------. Gnuplot is an amazingly capable program with the usual plethora of switches, options, codes, and hidden and secret corners only explored by university thesis writers, who occasionally publish a desultory web-page describing some serendipitous discovery. Gnuplot can make mathematical graphs and curves as well as bar-charts (histograms) along with lots of other things. In this book, the convention of writing '\\$>>' may be used to indicate commands which are entered from within the gnuplot interpreter. @@ \url{http://www.gnuplot.info/} The official home page of gnuplot @@ \url{http://www.ibm.com/developerworks/library/l-gnuplot/} a good tutorial @@ \url{http://sparky.rice.edu/gnuplot.html} an intro to gnuplot @@ \url{http://t16web.lanl.gov/Kawano/gnuplot/plot1-e.html} lots of info * start the interactive gnuplot shell >> gnuplot HISTORY Originally developed by Colin Kelley and Thomas Williams in 1986 GETTING HELP * view a general help menu with submenu selections >> help * get help for the gnuplot 'set xrange' command >> echo help set xrange | gnuplot * display test graphs with example linewidths and pointtypes >> test * view a list of all keywords setting with the 'set' command >> set * view a list of all possible options after the 'with' keyword >> plot x with COMMAND ABBREVIATIONS Any command can be abbreviated to any length as long as there is no ambiguity, that is, no other command which could be referenced by the same abbreviation (eg 'u' or 'usi' for using) . Other commands have and explicit abbreviation (eg 'lt' for 'linetype') \title{} \author{bumble.sourceforge.net} \maketitle \tableofcontents example .. using - 'u', 'usi', 'usin' are all valid abbreviations .. SIMPLE USAGE Gnuplot can be used either 'interactively' by starting the gnuplot program with the command 'gnuplot' or else it can be used in batch mode executing commands to create graphs. * start the gnuplot shell and plot a polynomial graph ---------------------------------------------------------- gnuplot \\# a welcome message is shown and a new 'gnuplot' prompt starts plot x**3 + x**2 + x + 1 \\#the graph is shown in a separate window quit \\# exit gnuplot, the graph window is also closed ,,, * plot a sin curve with x-axis (horizontal axis) -20 to 20 >> set xrange [-20:20] >> plot sin(x) * plot a surface with colorful lines >> echo "splot x*x-y*y with line palette" | gnuplot -persist * plot a parabola using pipes >> echo 'plot x**2' | gnuplot -persist * plot sin, cos and tan curves all on the same graph >> echo "plot sin(x),cos(x),tan(x)" | gnuplot -persist * plot a surface from the bash shell using an 'x' and 'y' range >> echo 'splot [x=-4:4] [y=-4:4] sin(x)*cos(y)' | gnuplot -persist * plot some random disk usage data of the current folder, labels rotated ---------------------------------------------------------------------- du -s * | shuf | head -10 > temp.txt echo ' set style data histogram set xtics rotate by -60 plot "temp.txt" using 1:xticlabels(2)' | gnuplot -persist ,,, The 'xticlabels' should refer to the field containing text (not numbers) * plot disk usage data from standard input >> (echo "set xtic rot;plot '-' u 1:xticl(2)"; du -s \\$\\verb|~|/*)|gnuplot -persist * a more verbose version of the same ------------------------------------ (echo " set xtics rotate by -45; plot '-' using 1:xticlabels(2)"; du -s \\$\\verb|~|/*)|gnuplot -persist ,,, * create an image of a sin curve graph and display it >> echo "se t png; se o 'o.png'; p sin(x)" | gnuplot; feh o.png * the same as above but more verbose >> echo "set terminal png; set output 'o.png'; plot sin(x)" | gnuplot; feh o.png * plot the graph 'sin(x)' as ascii text >> echo "set terminal dumb; plot x**2" | gnuplot -persist >> echo "se te du; p sin(x)" | gnuplot -persist \\#\\#(the same) COMMAND LINE OPTIONS AXIS VALUE RANGE * plot a sin curve with x-axis -20 to 20, all commands on one line >> set xrange [-20:20]; plot sin(x) >> plot [-20:20] sin(x) \\#\\#(the same) * plot a sin curve with x-axis -pi to pi ('pi' is a mathematical transcendental) >> set xrange [-pi:pi]; plot sin(x) >> plot [-pi:pi] sin(x) \\#\\#(almost the same) * plot the function 'y=x' with a y-axis range of [-2:5] >> plot [][-2:5] x >> plot [ ] [-2:5] x \\#\\#(the same, spaces dont matter) >> set yrange [-2:5]; plot x \\#\\#(the same, but persists for next graph) * set the x value range to 0 to a multiple of pi >> set xrange [0:2*pi] * plot from the command line a 'cos(x)' graph with x-range -20 to 20 >> echo 'plot [-20:20] cos(x)' | gnuplot -persist * create an image of 'sin(x)' with x-range -20 to 20 >> echo "se t png;se o 'i.png'; p[-20:20] sin(x)" | gnuplot;feh i.png * the same as above >> echo "set t png;set o 'o.png';plot [-20:20] sin(x)" | gnuplot;feh o.png USING THE GNUPLOT SHELL * plot a curve, add a title and then replot it (which saves some typing) >> plot sin(x); set title 'hello'; replot * span a single command over several lines with a backslash '\\$\\backslash\\$' >> set \\$\\backslash\\$ >> grid GRAPH TITLES The title of the graph normally appears above the graph and should describe it. Each curve or data set should also have a legend to explain it. * plot a graph of the sin curve with a graph title 'a simple curve' >> echo 'set title "Two Curve"; p sin(x),tan(x)' | gnuplot -persist * set the title for just one plot >> echo "plot x*x title 'a parabola'" | gnuplot -persist >> plot x*x t 'a parabola' \\#\\#(exactly the same) * create a multiline title for a half circle graph >> echo 'p [-2:2][0:2](1-x*x)**0.5 title "Half\\$\\backslash\\$nCircle"'|gnuplot -persist * plot a curve with the title 'x\\^2 + y\\^2' >> echo 'set title "x\\^2 + y\\^2"; splot x**2+y**2' | gnuplot -persist BORDERS AND FRAMES The border is the box which surrounds the graph and on which the tick marks are drawn. ERASING BORDERS .... To erase some or all or the borders of a graph one must use a sort of binary arithmetic. * remove all borders from the graph (but the ticks remain) >> set border 0 * display only the bottom and left borders, tic marks and labels >> echo "se bor 3; se tics nomirror; p sin(x)" | gnuplot -persist >> echo "se bor 3; se tics nomi; p sin(x)" | gnuplot -persist \\#\\#(the same) * display only the bottom and left borders, tic marks and labels >> set border 3; set xtics nomirror; set ytics nomirror >> set border 3; set tics nomirror \\#\\#(the same, with modern gnuplot) >> se bor 3; set tics nomirror \\#\\#(an abbreviated version) * show the bottom, left, right borders, but not the top, nor the top tics >> echo "se bor 11; se xtics nomi; p x**2" | gnuplot -persist * show no graph border, no tic marks and no value labels for a parabola >> unset tics; set border 0; plot x**2 >> set notics; set border 0; plot x**2 \\#\\#(an older syntax) * display only the bottom border for a parabola graph >> set border 1; plot x**2 \title{} \author{bumble.sourceforge.net} \maketitle \tableofcontents the graph border 'keys' .. 1 - bottom .. 2 - left .. 4 - top .. 8 - right .. \title{} \author{bumble.sourceforge.net} \maketitle \tableofcontents border examples .. set border 3 - (1+2) display bottom and left borders .. set border 6 - (2+4) display left and top borders .. set border 6 - (1+2+4) display bottom, left and top borders .. set border 11 - (1+2+8) display the bottom, left, and right borders .. AXIS LABELS The axis label is the text which is printed alongside of the vertical (y) or horizontal (x) axis. This text generally explains the meaning of the value of that axis, such as 'temperature' or 'date' etc. * The formal syntax statement ----------------------------- set xlabel \{"