When you want to highlight the difference between two curves or datasets, or show when your data values exceed some reference value, the filled curve style, with some encouragement, can be made to serve. The following figure shows an example of filled curves:
You can change the color (to blue, for example) by appending lt rgb blue
to the plotting command. If you want to change the fill style to use a pattern rather than a solid color, precede the plotting command with the following command:
In this command n
is an integer that specifies the fill style from those available in your terminal. To see a list of these, just issue the command test
.
Suppose you are plotting data from a file, and the data is arranged in a table in the following format:
You can fill in the difference between the two curves y versus x and z versus x with the following command:
Following is the complete script for creating the plot shown in the previous figure:
This plot shows the difference between a parabola and a straight line.
The fill pattern is similar to what you will get with the X11, Postscript, and some other terminals, but, as with all patterns and styles selected by an index number, this is dependent on the terminal. On the Macintosh using the Aquaterm terminal, for example, all the fill patterns are solid colors, and selecting an index merely changes the color.
The plot command used here exploits some features that we have not covered before. The using
keyword selects the column from the datafile; using 1:2:3
means to plot all columns, and the filledcurves
style knows how to fill in the difference between the curves in this case. After this, we plot the parabola and line separately, using a blank filename to select the previous name. The purpose of the last two plot components of the command is to plot the thick lines that delimit the filled area; the lw 3
chooses the line thickness, and the notitle
tells gnuplot not to add an entry into the legend for these plot components, which would be redundant.
But what if you want to make something similar to the previous figure without making an intermediate datafile? You can make a plot that fills the area between two functions by using gnuplot's special filenames. This is a facility that allows you to do things that normally can only be done with datafiles right on the command line or in a script, without having to make a datafile.
Following is another way to get the previous figure:
The +
refers to a fictitious datafile where the first column consists of the automatically calculated sample points.
We've already encountered another of gnuplot's special files, the file called ''
(an empty string), which refers to the previously named datafile, and we used it to avoid having to type its name multiple times.