Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
gnuplot Cookbook

You're reading from   gnuplot Cookbook Visual guide to every kind of graph you can make with this plotting software with this book and ebook

Arrow left icon
Product type Paperback
Published in Feb 2012
Publisher Packt
ISBN-13 9781849517249
Length 220 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Lee Phillips Lee Phillips
Author Profile Icon Lee Phillips
Lee Phillips
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

gnuplot Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Plotting Curves, Boxes, Points, and more FREE CHAPTER 2. Annotating with Labels and Legends 3. Applying Colors and Styles 4. Controlling your Tics 5. Combining Multiple Plots 6. Including Plots in Documents 7. Programming gnuplot and Dealing with Data 8. The Third Dimension 9. Using and Making Graphical User Interfaces 10. 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.

Getting ready

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
You have been reading a chapter from
gnuplot Cookbook
Published in: Feb 2012
Publisher: Packt
ISBN-13: 9781849517249
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime