You're reading from gnuplot Cookbook
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.
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
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...
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.
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
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.
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
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:
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...