Reader small image

You're reading from  gnuplot Cookbook

Product typeBook
Published inFeb 2012
PublisherPackt
ISBN-139781849517249
Edition1st Edition
Tools
Right arrow
Author (1)
Lee Phillips
Lee Phillips
author image
Lee Phillips

Lee Phillips grew up on the 17th floor of a public housing project on the Lower East Side of Manhattan. He attended Stuyvesant High School and Hampshire College, where he studied Physics, Mathematics, and Music. He received a Ph.D. in 1987 from Dartmouth in theoretical and computational physics for research in fluid dynamics. After completing post-doctoral work in plasma physics, Dr. Phillips was hired by the Naval Research Laboratory in Washington, DC, where he worked on various problems, including the NIKE laser fusion project. Dr. Phillips is now the Chief Scientist of the Alogus Research Corporation, which conducts research in the physical sciences and provides technology assessment for investors.
Read more about Lee Phillips

Right arrow

Chapter 5. Combining Multiple Plots

This chapter contains the following recipes:

  • Arranging an array of plots

  • Positioning plots manually

  • Creating an inset plot

  • Multiplotting with labels and arrows

Introduction


This chapter will show you how to combine several plots into a larger visualization using gnuplot's multiplot mode. This is a flexible facility that allows you to place a set of plots anywhere on the page, in a regular array, or one inside the other.

Arranging an array of plots


The simplest use of the multiplot mode creates a rectangular array of plots with regular spacing. The following figure is an example of this type of multiple plot:

In the previous figure, we have made a table of graphs showing the four kinds of Bessel function that gnuplot has built in.

How to do it…

Run this script through gnuplot to get the array of plots shown in the previous figure:

set multiplot layout 2, 2
plot besj0(x)
plot besj1(x)
plot besy0(x)
plot besy1(x)
unset multiplot

How it works…

The new command is in the first line of the recipe. The commands following that are simple plot statements, until we reach the final line. The initial command puts gnuplot into multiplot mode. If you are working interactively, you will see that the prompt, which is usually gnuplot>, has become multiplot> to remind you that you are in a special mode.

The layout 2, 2 part of the command sets up a regular array of plots with two columns and two rows; of course you can use...

Positioning plots manually


If you need an arrangement of figures other than a regular rectangular array, you must specify the origin and size for each plot manually. The following figure provides an example:

The happy face shown in the previous figure is a simple example of what you can achieve with manual plot positioning; using these commands, figures of frightening complexity can be built up.

How to do it…

The following script shows how to use gnuplot's manual positioning commands:

set multiplot
unset key
unset tics
set polar
set size 1, .5
plot [pi:2*pi] 1 lw 5
set origin 0, .5
set size .5, .5
plot 1 lw 2, .2 with filledcurves
set origin .5, .5
plot 1 lw 2, .2 with filledcurves
unset multiplot

How it works…

Arbitrary sizing and positioning of individual plots is accomplished using the two new commands that we have highlighted in the previous script. After entering multiplot mode, the set origin command can be used to set the position of the lower-left corner of the next plot. The set size...

Creating an inset plot


A common pattern is a graph enclosing another smaller graph that reveals a detail in the larger graph by plotting it using a magnified scale. Following is an example:

In the previous figure, the smaller plot is usually called an inset. We can create this figure with the script given in the following How to do it... section.

How to do it…

The following script produces the previous figure:

set multiplot
set object ellipse center .13, 0 size .4, 4
set arrow from .1, 2.1 to screen .22, .4 front lt 3
set samples 1000
set grid
set xtics .4
set ytics 4
plot [0:2*pi] exp(x)*sin(1/x)
set origin .2, .4
set size .25,.25
clear
unset key
unset grid
unset object
unset arrow
set xtics .1
set ytics .5
set bmargin 1
set tmargin 1
set lmargin 3
set rmargin 1
plot [0:.2] exp(x)*sin(1/x)
unset multiplot

How it works…

There are few new commands here. We have simply combined several things covered earlier in order to create an illustration consisting of a large graph, an inset, and a device consisting...

Multiplotting with labels and arrows


In this recipe, we show how to create a complete illustration that might be useful in a calculus textbook, using arrows and the screen coordinate system to lead the eye around a cycle of graphs. The following figure shows what happens when we take successive derivatives of a sine wave:

How to do it…

The following script will give you the previous figure:

set xrange [-pi:pi]
unset key
set multiplot layout 2,2 title "Derivatives of Sin(x)" font "Times-Roman, 22"
set style arrow 1 head filled size screen 0.03,15,135 lt 2 lw 2
set arrow 1 from screen .45, .84 to screen .65, .84 arrowstyle 1
set arrow 2 from screen .87, .64 to screen .87, .3 arrowstyle 1
set arrow 3 from screen .7, .15 to screen .4, .15 arrowstyle 1
set arrow 4 from screen .35, .35 to screen .35, .7 arrowstyle 1
set title "sin(x)"
plot sin(x)
set title "sin\'(x) = cos(x)"
plot cos(x)
set title "sin\'\'\'(x) = cos\'\'(x) = -sin\'(x) = -cos(x)"
plot -cos(x)
set title "sin\'\'(x) = cos\'(x) = -sin...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
gnuplot Cookbook
Published in: Feb 2012Publisher: PacktISBN-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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Lee Phillips

Lee Phillips grew up on the 17th floor of a public housing project on the Lower East Side of Manhattan. He attended Stuyvesant High School and Hampshire College, where he studied Physics, Mathematics, and Music. He received a Ph.D. in 1987 from Dartmouth in theoretical and computational physics for research in fluid dynamics. After completing post-doctoral work in plasma physics, Dr. Phillips was hired by the Naval Research Laboratory in Washington, DC, where he worked on various problems, including the NIKE laser fusion project. Dr. Phillips is now the Chief Scientist of the Alogus Research Corporation, which conducts research in the physical sciences and provides technology assessment for investors.
Read more about Lee Phillips