This is an old revision of the document!
Download the following sets of data: data1.txt and data2.txt, and update gnuplot:
$ sudo apt-get install gnuplot
Start gnuplot by using the command:
$ gnuplot
The default terminal type is dependent on your environment. One of the recommended terminal types in terms of flexibility and functionality is wxt enhanced. To set the terminal type use:
gnuplot> set terminal wxt enhanced
If setting the terminal to wxt enhanced doesn't work, use the default terminal. If it is desired to display the terminal parameters at any point, use:
gnuplot> show terminal
Plot the sets of data found in data1.txt and data2.txt on the same graph:
gnuplot> plot 'data1.txt', 'data2.txt
'
In case the window plot does not appear, you might be missing gnuplot-x11. Try installing it:
$ sudo apt-get install gnuplot-x11
Set a title for the plot:
gnuplot> set title 'Example 1
'
Plot the data again for the title to appear. Notice that Gnuplot automatically selects different colours for each dataset. Change the colour for both datasets to black. This can be done with the lc parameter (stands for line colour). The command below changes the colour of the data from data2.txt to black.
gnuplot> plot 'data1.txt', 'data2.txt' lc rgb 'black
'
The next step is to assign label names to the two axis:
gnuplot> set xlabel 'X Label'
'
gnuplot> set ylabel 'Y Label'
gnuplot> plot 'data1.txt' lc rgb 'black', 'data2.txt' lc rgb 'black
The top-right corner of the plot area displays the names of the files containing the data, along with the symbol type associated with each data file. This is usually not something you would want to have on a plot. To remove it use:
gnuplot> unset key
'
gnuplot> plot 'data1.txt' lc rgb 'black', 'data2.txt' lc rgb 'black
If you want to set it back you can use the set key command:
gnuplot> set key
The text of the keys can be changed when plotting the data like this:
gnuplot> plot 'data1.txt' lc rgb 'black' title 'Data 1', 'data2.txt' lc rgb 'black' title 'Data 2
'
This is how the plot should look like so far:
It can be noticed that the data is obscuring the keys. In order to get the data off the keys, we can increase the Y axis to go all the way to 900. The X and Y ranges can be set as follows, using hard brackets and separating the low and high ranges by semicolon:
gnuplot> plot [:] [:900] 'data1.txt' lc rgb 'black' title 'Data 1', 'data2.txt' lc rgb 'black' title 'Data 2
'
There is a gap showing on the right-hand side of the graph. This can be eliminated by setting the high range for the X axis to the number of rows in the data files which is 1024:
gnuplot> plot [:1024] [:900] 'data1.txt' lc rgb 'black' title 'Data 1', 'data2.txt' lc rgb 'black' title 'Data 2
'
Saving the plot to an encapsulated postscript (eps is a vector graphic that can used in Latex documents) can be done as follows:
gnuplot> set terminal postscript eps enhanced “Helvetica” 24
gnuplot> set output 'exercise1.eps'
gnuplot> replot
Exit gnuplot, and notice that exercise1.eps was created. Open it and check how it looks.