A Brief GNUPLOT tutorial for EECS 380, Winter 2001 Prof. Mark Brehob and Prof. Igor Markov For more detailed information, see http://www.cs.dartmouth.edu/gnuplot_info.html and demos at http://www.cs.dartmouth.edu/gnuplot/gnuplot_d.html Post questions to the EECS 380 newsgroup ---- CONTENTS 1. Introduction 2. How to run GNUPLOT remotely 3. Simple tricks with GNUPLOT 4. Producing PostScript plots for printing 5. More advanced features ---- 1. Introduction GNUPLOT is free and distributed with most Unix operating systems (including Solaris and Linux). A Windows version is available (you can also use gnuplot on a remote Unix workstation and upload generated image files onto your Windows computer). We will use GNUPLOT to visualize various aspects of algorithms, in particular, their complexity. To run gnuplot on a CAEN Unix system, type gnuplot To quit gnuplot type quit Typing help while in GNUPLOT will bring online help You can also type help , for example help help, help plot or help plot example GNUPLOT and also run scripts. In this case, you prepare a text file, e.g., script.gpl and then type gnuplot script.gpl This is just a way to save typing for repeated operations with gnuplot 2. How to run GNUPLOT remotely If you are physically at CAEN and are using the screen of one of CAEN workstations, you do not need to read this section. If you are logging into CAEN remotely from a Unix workstation elsewhere, you need to enable a remote graphics connection to use GNUPLOT. For that, on the CAEN computer type uname -n The computer's name will be printed, for example and.engin.umich.edu On the computer whose screen you are using, type xhost + and.engin.umich.edu (use the name returned by uname -n) Similarly, find the name of the computer you are using. In my case, it is gagarin.eecs.umich.edu On the CAEN computer type setenv DISPLAY gagarin.eecs.umich.edu:0.0 If you are using a Windows computer, you can run gnuplot on a remote Unix machine without displaying pictures (this is possible too, but requires installing an "X server" on your Windows computer). gnuplot can save graphics into PostScript files which can then be uploaded to your Windows computer and viewed, e.g., with ghostview, which is easy to install. 3. Simple tricks with GNUPLOT Type gnuplot you will see a banner and then a prompt gnuplot> at the prompt, type plot x**2 you will see a parabola (x-squared), now try plot exp(x)*sin(10*x) plot [0:3] exp(x)*sin(10*x) this restricts x to the segment from 0 to 3 now type (7 lines) plot "-" 1 1 2 4 3 9 4 16 5 25 END This plots the five datapoints. To connect them with lines, add with lines to the first line You could also save all datapoints into a file named "data.xy" and type plot "data.xy" with lines, x**2 As you see, the function represented by datapoints is practically the same as x-squared To make your plot more readable, use the following command *before* the plot command set xlabel "Size of the input" set ylabel "Program runtime" set title "EECS 380, student's First_Name Last_Name, Homework/Project such and such" Specific labels will be different. Remember for each command (such as set, set xlabel and so on) you can use online help by typing help in front of the command on the same line. 4. Producing PostScript files for printing Once you are satisfied with how the plot looks on your screen, you can save it into a postscript file for printing. set terminal postscript portrait set output "output.ps" replot will save a black-and-white picture into file "output.ps" using dashed lines instead of colors (if you used "-" in your plot command, you will need to retype the datapoints). You will need to submit printouts of plots with your homeworks. 5. Type help plot and study other features of the plot command. Some examples are given at http://www.cs.dartmouth.edu/gnuplot/gnuplot_d.html Here is another example plot [0:5][0:5] "-" title "square1" w l, "-" title "square2" w l 1 1 1 2 2 2 2 1 1 1 END 3 2 3 3 4 3 4 2 3 2 END w l is an abbreviated with lines In order to draw multiple disconnected lines using one datafile, insert empty lines in the datafile.