#### Overview of this book

gnuplot is the world's finest technical plotting software, used by scientists, engineers, and others for many years. It is in constant development and runs on practically every operating system, and can produce output in almost any format. The quality of its 3d plots is unmatched and its ability to be incorporated into computer programs and document preparation systems is excellent. gnuplot Cookbook ñ it will help you master gnuplot. Start using gnuplot immediately to solve your problems in data analysis and presentation. Quickly find a visual example of the graph you want to make and see a complete, working script for producing it. Learn how to use the new features in gnuplot 4.4. Find clearly explained, working examples of using gnuplot with LaTeX and with your own computer programming language. You will master all the ins and outs of gnuplot through gnuplot Cookbook. You will learn to plot basic 2d to complex 3d plots, annotate from simple labels to equations, integrate from simple scripts to full documents and computer progams. You will be taught to annotate graphs with equations and symbols that match the style of the rest of your text, thus creating a seamless, professional document. You will be guided to create a web page with an interactive graph, and add graphical output to your simulation or numerical analysis program. Start using all of gnuplot's simple to complex features to suit your needs, without studying its 200 page manual through this Cookbook.
gnuplot Cookbook
Credits
www.PacktPub.com
Preface
Free Chapter
Plotting Curves, Boxes, Points, and more
Annotating with Labels and Legends
Applying Colors and Styles
Combining Multiple Plots
Programming gnuplot and Dealing with Data
The Third Dimension
Using and Making Graphical User Interfaces
Surveying Special Topics
Finding Help and Information
Index

## Making a statistical whisker plot

Also known in the statistics world as a "box and whisker plot" or simply as a boxplot, the statistical whisker plot is a series of symbols, each one showing the mean value of a set of measurements, the extent of the central part of the measurements' or population's distribution, and the extent of the remainder of the distribution excluding the "outliers" (the outliers themselves are sometimes shown as dots, but we won't use that style here). This type of plot is also sometimes used for financial price data rather than the finance plot that was the subject of the Handling financial data recipe in this chapter. We will avoid the specialized language of statistics and further discussion of the uses of these plots, but the statisticians among our readers know why they're here. The following figure shows the depiction of a statistical whisker plot using gnuplot:

In the previous plot, typically, the boxes show the range of the central part of the data distribution; the short horizontal line within the boxes shows the value of the mean; and the vertical lines extending above and below the boxes show the range of the bulk of the distribution excluding the outliers.

We've borrowed the demo file `candlesticks.dat` that comes with the gnuplot distribution; make sure it's in your current directory. If you want to use your own data instead, each line of the file must be in the following format:

`x  whisker_min  box_min  mean  box_high   whisker_high`

### How to do it…

Feed the following script to gnuplot to get the whisker plot:

```set xrange [0:11]
set yrange [0:10]
set boxwidth 0.2
plot 'candlesticks.dat' using 1:3:2:6:5 with candlesticks lt -1 lw 2 whiskerbars,\
'' using 1:4:4:4:4 with candlesticks lt -1 lw 2 notitle```

### How it works…

The first two lines set the x and y ranges of the axes; they are set to give a little room around the data. The next line sets the `boxwidth`—the width of the rectangle showing the extent of the central part of the distribution (the default is very skinny). Next comes the plot command, split here over two lines. The order of the fields expected by the candlestick style is `x` `box_min` `whisker_min` `whisker_high` `box_high`, which is not in the same order as our datafile, so we need to use the `using` command to put the columns in the right order for plotting. The first plot command also specifies the line type `lt` to be `-1` for solid black and a line width is set to `2`; whiskerbars means put the little caps on the end of the whiskers. The second plot command—starting on the last line—plots from the same datafile, but employs a trick to use the 4th column—containing the mean value—repeatedly, effectively collapsing the box ends and whiskers down to the mean, all just to plot the little horizontal line in the middle of the boxes. This may seem like a convoluted method, but it ensures that the lines indicating the mean values are in the right places and have exactly the correct width to lie within the boxes.

### There's more…

Some people prefer their whisker plot boxes to be filled in with a solid color or pattern. To get this, before issuing the plot command try the following command:

`set style fill solid`

or

`set style fill pattern n`