Saving and Using Scripts

A script is just a collection of gnuplot commands -- the same commands you would type in to an interactive session. Scripts are useful because they specify exactly what commands went into producing a plot, for future reference.

You can create a script by hand using any text editor or you can have gnuplot save a record of what you have done with the command

	save "script-name"
which writes all relevant commands leading to the most recent plot into the specified file.

To use a script, either place its name on the gnuplot command line, or enter the command

	load "script-name"
at the gnuplot prompt.

A typical simple script might look like:

	set title "overall label"
	set xlabel "time"
	set ylabel "data"

	set nokey	# turn keys off -- this is a comment, by the way!

	plot [1:13] [-1:1] "data1" every 4 using 1:3 with points
Run it by typing
	gnuplot -persist script-name


If you like, you can make this script into an executable program by adding the line
	#!/usr/local/bin/gnuplot -persist
at the start, and making the script executable:
	chmod a+x script-name
The initial line tells Linux how to run the script. This approach has several advantages -- for example you can pipe data into the script and simply have plot use "-" as a file name, avoiding any need to know the data file name in advance.