Intro to Scientific Computing

PHYS 27/193

Physics Department
University of the Pacific

Saving and Printing

Saving your Work

Often you need to stop your work where you are (maybe to Sleep!) and save it, so you can come back to the project later.

There are two different aspects to saving.

Saving a Plot to re-Load it later

If you want to save a plot so that you easily reproduce it later, you use the save command. Once you have a plot that you like, you simply do:

gnuplot> save "myplot.gp"
This will create a new text file named "myplot.gp" in the present working directory (remember pwd).
Since it's a text file, you can easily look at it, and even edit it if you wanted.

Try it. Make a plot of your favorite function, then save it as shown above.

Have a look at this file with less.


An easy way to do this is to "CTRL-z" out of gnuplot. This is another bit of Unix magic.

At the gnuplot prompt, type CTRL-z

This should pop you out of gnuplot (actually it suspends gnuplot and gives you back your xterm prompt). At the xterm prompt, you can do less myplot.gp, have a look at your file. Notice in particular the last lines which have the plot command that you used to make your graph.

When your done looking at your file, your can bring gnuplot back by putting it in the foreground. At the xterm prompt, type fg then ENTER. You should now have your gnuplot> prompt back.


Now, you can shut down your computer, go to a concert (maybe like Porcupine Tree, who I saw in San Francisco recently!),
and come back to your scientific work tomorrow.

To see your plot again, cd to the folder where "myplot.gp" is, start gnuplot, and do:

gnuplot> load "myplot.gp"

This should popup the graph window with your previous plot showing.
Remember that all file or directory names must be enclosed in ""s.

This method is used when you wish to save to gnuplot commands which produced an individual plot. If you have done a fit, the function which you have defined will be in the saved file, along with the "best fit" parameters which were found. Note that when you do a fit, gnuplot saves a complete log in the file "fit.log". Only the log of the last fit is saved however.

Saving your entire gnuplot session

As we did in HW 5, if you want to save a complete record of all the commands you have typed during your session, you can do the following:

gnuplot> history "mysession.gp"

This will create a (possibly long) file called "mysession.gp" with all the commands you have typed into gnuplot. If you view this file in less, you can read what you had been doing, and cut/paste commands into gnuplot to redo the things you want.

Saving a plot as an image

Another very useful save method is to "write the plot in a different format, for example as a GIF graphics file.

Gnuplot has many different Terminals for which it can produce plots. Since gnuplot has been around for 20 years, several of these are outdated. However, a few are quite useful; the PDF "terminal" is one of these, for example.

To see all the terminal types, do

gnuplot>set term
as if you were going to set the terminal to some type. But just type ENTER instead.
This will list all the possible terminal types. I've highlighted common ones below:
Available terminal types:
           aed512  AED 512 Terminal
           aed767  AED 767 Terminal
             aifm  Adobe Illustrator 3.0 Format
         bitgraph  BBN Bitgraph Terminal
              cgm  Computer Graphics Metafile
            corel  EPS format for CorelDRAW
             dumb  ascii art for anything that prints text
              dxf  dxf-file for AutoCad (default size 120x80)
            eepic  EEPIC -- extended LaTeX picture environment
              emf  Enhanced Metafile format
            emtex  LaTeX picture environment with emTeX specials
         epslatex  LaTeX picture environment using graphicx package
     epson_180dpi  Epson LQ-style 180-dot per inch (24 pin) printers
      epson_60dpi  Epson-style 60-dot per inch printers
      epson_lx800  Epson LX-800, Star NL-10, NX-1000, PROPRINTER ...
              fig  FIG graphics language for XFIG graphics editor
           gif  GIF images using libgd and TrueType fonts
             gpic  GPIC -- Produce graphs in groff using the gpic preprocessor
          hp2623A  HP2623A and maybe others
           hp2648  HP2648 and HP2647
           hp500c  HP DeskJet 500c, [75 100 150 300] [rle tiff]
             hpdj  HP DeskJet 500, [75 100 150 300]
             hpgl  HP7475 and relatives [number of pens] [eject]
           hpljii  HP Laserjet series II, [75 100 150 300]
             hppj  HP PaintJet and HP3630 [FNT5X9 FNT9X17 FNT13X25]
           imagen  Imagen laser printer
          jpeg  JPEG images using libgd and TrueType fonts
       kc_tek40xx  MS-DOS Kermit Tek4010 terminal emulator - color
       km_tek40xx  MS-DOS Kermit Tek4010 terminal emulator - monochrome
            latex  LaTeX picture environment
               mf  Metafont plotting standard
              mif  Frame maker MIF 3.00 format
               mp  MetaPost plotting standard
          nec_cp6  NEC printer CP6, Epson LQ-800 [monocrome color draft]
          okidata  OKIDATA 320/321 Standard
              pbm  Portable bitmap [small medium large] [monochrome gray color]
             pcl5  HP Designjet 750C, HP Laserjet III/IV, etc. (many options)
           pdf  PDF (Portable Document File) file driver
              png  PNG images using libgd and TrueType fonts
       postscript  PostScript graphics, including EPSF embedded files (*.eps)
          pslatex  LaTeX picture environment with PostScript \specials
            pstex  plain TeX with PostScript \specials
         pstricks  LaTeX picture environment with PSTricks macros
              qms  QMS/QUIC Laser printer (also Talaris 1200 and others)
            regis  REGIS graphics language
             rgip  RGIP metafile (Uniplex). Option: fontsize (1-8)
          selanar  Selanar
            starc  Star Color Printer
              svg  W3C Scalable Vector Graphics driver
      tandy_60dpi  Tandy DMP-130 series 60-dot per inch graphics
          tek40xx  Tektronix 4010 and others; most TEK emulators
          tek410x  Tektronix 4106, 4107, 4109 and 420X terminals
          texdraw  LaTeX texdraw environment
             tgif  TGIF X11 [mode] [x,y] [dashed] ["font" [fontsize]]
         tkcanvas  Tk/Tcl canvas widget [perltk] [interactive]
             tpic  TPIC -- LaTeX picture environment with tpic \specials
          uniplex  RGIP metafile (Uniplex). Option: fontsize (1-8) (Same as rgip)
          unknown  Unknown terminal type - not a plotting device
            vttek  VT-like tek40xx terminal emulator
           x11  X11 Window System
             xlib  X11 Window System (gnulib_x11 dump)
This is what you get by typing the set term command.

To use one of these terminal types, you start gnuplot and get plot what you want.

After you have the plot looing the way you want it to,
you can produce a GIF image of your plot by doing the following:

gnuplot> set terminal gif         # sets the terminal to GIF
gnuplot> set output "myplot.gif"  # sets the output to a file called "myplot.gif"
gnuplot> replot                   # plots the GIF file to "myplot.gif"
gnuplot> unset output             # unset file output   
gnuplot> set terminal pop         # return terminal type to default
(of course you don't need to type the #comments shown above)

The last line above, set terminal pop, returns the terminal type to the one that was set when gnuplot stated.

Do this for a plot of your choice (say, sin(x) if you can't think of a more interesting one).

Next, find and (double) click on the GIF file you made. Your computer should start its default image software to display the image.
You can now include this image in a document or webpage, or send it to a collaborator via email.

GIF and JPEG files are useful for including other documents such as HTML web pages or MS Word documents.
Another very popular file format at the moment is PDF (viewed with Adobe Reader).
You can make a PDF file of your plot by following the steps above, but using pdf instead of gif.

gnuplot> set terminal pdf         
gnuplot> set output "myplot.pdf"  
gnuplot> replot                   
gnuplot> unset output             
gnuplot> set terminal pop         

Be sure you can make a plot in PDF format. Then find it an view it with your PDF viewer.
You'll need to send me a PDF plot later, and we'll use JPEG plots in LaTeX.


Printing your Plots

The methods above are almost enough to do everything, but there are times when you just need to send your Mom a copy of some really interesting work that you've recently done, so she can put it on the 'fridge to display for her friends.

There simplest method to Print a Plot is to just produce a PDF file as described above, find the file with a PDF Reader, and print the file from the Reader.

So, are you ready to put all this together? Here's Homework 6