gnuplotGNUPLOT will respond with a header and the command prompt
gnuplot>While there are numerous plotting options available in GNUPLOT, the simplest form of a GNUPLOT plotting command is
plot <function>For example,
plot sin(x)To erase the plot from the screen and return to command mode, press any key. If you are running GNUPLOT as an X client, this will not be necessary as the plot will appear in a separate window.
You can also add a range for the abscissa, the ordinate and add a title.
plot [<xrange>] [yrange] <function> title <title>For example, specifying the x range and a title
plot [-pi:pi] cos(x) title "Cosine Function"To place labels on the plot, use the "set label" command.
set label <label number> "<:text>" at x,y,zwhere x,y and z are values in the graph's coordinate system and where z is only used for a 3-d plot, using the "splot" command. For example,
set label 1 "Fahrenheit" at 150,140 set label 2 "Centigrade" at 150,50To label the X and/or Y axes, use the "xlabel", "ylabel" commands. For example
set xlabel "Time - Seconds" set ylabel "Temperature"Note that you must define labels before you plot the graph. You cannot add labels after the plot is created. Here's an example using all of the above options and also illustrating how you can define functions in GNUPLOT.
tempf(t) = t tempc(t) = 5./9*(tempf(t)-32) set label 1 "Fahrenheit" at 150,140 set label 2 "Centigrade" at 150,50 set xlabel "Time - Seconds" set ylabel "Temperature" set title "Temperature vs. Time" plot [t=32:212] tempf(t),tempc(t) Note (1): By using the "set title" command in lieu of including the title in the plot command, the title on the plot is centered. Note (2): If you wish to make changes after the plot is created (e.g., label, xlabel), you can replot the function(s) with the "replot" command.Three dimensional plotting is done using the "splot" command. Here is an example.
set title "Sine Cosine Envelope" set xlabel "X" set ylabel "Y" set zlabel "Z" splot [x=-pi:pi] [y=-pi:pi] cos(x-y)*cos(x+y),-1+sin(x-y)*sin(x+y) Note: If the range is not used in the plot or the splot command, these commands will use the values defined in previous commands. For example, if the command "splot cos(x)+sin(y)" were issued following the splot command in the above example, the range for x and y would be from -pi to pi. If the range is not defined in any previous commands, GNUPLOT computed default values are used.The example presented here as well as subsequent examples are intended to help you get a quick start to using GNUPLOT. This program document is not intended as a substitute to the full GNUPLOT documentation. For a detailed description of the commands illustrated here as well as all of the GNUPLOT commands see the GNUPLOT manual or use the on-line help facility: type "help help" at the GNUPLOT prompt for information.
set termThis can also be accomplished by defining "term" in the GNUPLOT startup file, ".gnuplot" on the Unix systems. The startup file must reside in your home directory. This file can also be used to define functions and variables that are often used. Below is a list of the commonly` used terminal types at the university and the associated values of "term".
Terminal Type term ------------- ---- x11 Window System x11 Kermit tek40xx Terminal Emulation kc_tek40xx (color) km_tek40xx (monochrome) Em4105 Terminal Emulation tek410x DOS system (Smith Hall Novell Network) vgabiosNote that if you do not have "term" set either by having an entry in a GNUPLOT startup file or by setting term after you begin running GNUPLOT, GNUPLOT will request that you set "term" before any graphics can be displayed. An exception to this is under X Windows. In this case, GNUPLOT will detect that you are running under X and set term to x11.
set termTo obtain hardcopy output, you must reset "output" either to a local printer or to a remote printer. A local printer is one that is directly connected to the computer on which you are running GNUPLOT. A remote printer is one that is connected to a remote computer. Running GNUPLOT on Strauss with output directed to smips is an example of using a local printer. Running GNUPLOT on Strauss with output directed to a printer in your office is an example of using a remote printer. As shown below, on a Unix system, "output" is actually set to a print command rather than a printer. For a local printer the print command is "lpr" or "qpr -q
set output "|and for a remote printer"
set output "| rsh" where <remotecomputer> is the name of the remote computer with an attached printer to which you are directing your output and where <printcommand> is replaced by the appropriate print command as illustrated in the following: lpr Appropriate on a Unix system with a printer attached where the command for hardcopy is "lpr ". For example, a workstation in the Smith Hall Sun Lab. qpr -q Appropriate on a Unix system with a mdqs printer attached. For example, to access the Smith Hall PostScript printer connected to Strauss, replace with "smips".
gnuplot . plot sin(x) set output "| qpr -q smips" <- direct output to smips set term postscript <- define the output device as PostScript) replot <- replot last graph set output <- reset output back to the screen set term x11 <- reset the device back to X-Windows . Note: See Note (2) following the examples for a shortcut to issuing the commands above that set and reset the variables "output" and "term". Note: In this example and the examples to follow, hardcopy of the plots is piped directly to a printer. This eliminates the extra step of first saving the output to a file. However, in some cases, you may want to save the output as well as printing it. In this case, set the output variable to a file name of your choice. For example, set output "example1.ps"After the GNUPLOT session is over, you can get hardcopy of the plot by printing the file. For example,
qpr -q smips example1.ps
gnuplot set term tek40xx . plot sin(x) set output "| rsh some.remote.computer.name lpr" * set term postscript replot set output set term tek40xx . * See Note (1) below.
(Kermit: Select unix, udelnet and set terminal flow control to software via the command: "terminal flowcontrol software", logon to Strauss) gnuplot set term kc_tek40xx . plot sin(x) set output "| qpr -q smips" set term postscript replot set output set term kc_tek40xx (Use "km_tek40xx for a monochrome display) .
(Use the setup for Kermit above, replacing "kc_tek40xx" with "tek410x")Note 1: For the "rsh" command to work in example (2), it is necessary to have an .rhosts file resident in your home directory on the remote computer with the address of your local computer and your login name on the local computer. Note 2: Generally when you generate hardcopy, you first plot the graph on the screen, then replot it sending the output to the hardcopy device and finally reset the terminal parameters "term" and "output". Rather than repeating this sequence of 5 commands, it is easier to copy these commands to a file which can be loaded in and executed with one command. For example, suppose you have a Sun Workstation in your office with a printer attached. You run GNUPLOT on Strauss. Sometimes you would like the hardcopy to go to the Smith Hall laser printer, smips, and other times to your office PostScript printer. Assume that your office workstation has an address: "mysun.ournet.udel.edu". Then, you could create the following two files on Strauss: file: usesmips set output "| qpr -q smips" set term postscript replot set output set term x11 file: usemyprtr set output "| rsh mysun.ournet.udel.edu lpr" set term postscript replot set output set term x11 Then, to send hardcopy output of a graph to smips, you would type plot cos(x) title "This graph will be printed at Smith Hall" load "usesmips" and to produce hardcopy at your office printer plot cos(x) title "This graph will be printed on my office printer" load "usemyprtr" Note 3: On most systems, hardcopy will not be sent to the printer until the variable "output" is reset. For example, in Example (3) after the replot command is issued, hardcopy will not be printed on the Sun Lab printer until the command "set output" is reissued.