Multiplot

The command set multiplot places gnuplot in the multiplot mode, in which several plots are placed next to each other on the same page or screen window.

Syntax:

     set multiplot
         { title <page title> {font <fontspec>} {enhanced|noenhanced} }
         { layout <rows>,<cols>
           {rowsfirst|columnsfirst} {downwards|upwards}
           {scale <xscale>{,<yscale>}} {offset <xoff>{,<yoff>}}
           {margins <left>,<right>,<bottom>,<top>}
           {spacing <xspacing>{,<yspacing>}}
         }
     set multiplot {next|previous}
     unset multiplot

For some terminals, no plot is displayed until the command unset multiplot is given, which causes the entire page to be drawn and then returns gnuplot to its normal single-plot mode. For other terminals, each separate plot command produces an updated display.

The clear command is used to erase the rectangular area of the page that will be used for the next plot. This is typically needed to inset a small plot inside a larger plot.

Any labels or arrows that have been defined will be drawn for each plot according to the current size and origin (unless their coordinates are defined in the screen system). Just about everything else that can be set is applied to each plot, too. If you want something to appear only once on the page, for instance a single time stamp, you'll need to put a set time/unset time pair around one of the plot, splot or replot commands within the set multiplot/unset multiplot block.

The multiplot title is separate from the individual plot titles, if any. Space is reserved for it at the top of the page, spanning the full width of the canvas.

The commands set origin and set size must be used to correctly position each plot if no layout is specified or if fine tuning is desired. See set origin (p. [*]) and set size (p. [*]) for details of their usage.

Example:

     set multiplot
     set size 0.4,0.4
     set origin 0.1,0.1
     plot sin(x)
     set size 0.2,0.2
     set origin 0.5,0.5
     plot cos(x)
     unset multiplot

This displays a plot of cos(x) stacked above a plot of sin(x).

set size and set origin refer to the entire plotting area used for each plot. Please also see set term size (p. [*]). If you want to have the axes themselves line up, you can guarantee that the margins are the same size with the set margin commands. See set margin (p. [*]) for their use. Note that the margin settings are absolute, in character units, so the appearance of the graph in the remaining space will depend on the screen size of the display device, e.g., perhaps quite different on a video display and a printer.

With the layout option you can generate simple multiplots without having to give the set size and set origin commands before each plot: Those are generated automatically, but can be overridden at any time. With layout the display will be divided by a grid with 4#4rows5#5 rows and 4#4cols5#5 columns. This grid is filled rows first or columns first depending on whether the corresponding option is given in the multiplot command. The stack of plots can grow downwards or upwards. Default is rowsfirst and downwards. The commands set multiplot next and set multiplot previous are relevant only in the context of using the layout option. next skips the next position in the grid, leaving a blank space. prev returns to the grid position immediately preceding the most recently plotted position.

Each plot can be scaled by scale and shifted with offset; if the y-values for scale or offset are omitted, the x-value will be used. unset multiplot will turn off the automatic layout and restore the values of set size and set origin as they were before set multiplot layout.

Example:

     set size 1,1
     set origin 0,0
     set multiplot layout 3,2 columnsfirst scale 1.1,0.9
     [ up to 6 plot commands here ]
     unset multiplot

The above example will produce 6 plots in 2 columns filled top to bottom, left to right. Each plot will have a horizontal size of 1.1/2 and a vertical size of 0.9/3.

Another possibility is to set uniform margins for all plots in the layout with options layout margins and spacing, which must be used together. With margins you set the outer margins of the whole multiplot grid.

spacing gives the gap size between two adjacent subplots, and can also be given in character or screen units. If a single value is given, it is used for both x and y direction, otherwise two different values can be selected.

If one value has no unit, the one of the preceding margin setting is used.

Example:

     set multiplot layout 2,2 margins 0.1, 0.9, 0.1, 0.9 spacing 0.0

In this case the two left-most subplots will have left boundaries at screen coordinate 0.1, the two right-most subplots will have right boundaries at screen coordinate 0.9, and so on. Because the spacing between subplots is given as 0, their inner boundaries will superimpose.

Example:

     set multiplot layout 2,2 margins char 5,1,1,2 spacing screen 0, char 2

This produces a layout in which the boundary of both left subplots is 5 character widths from the left edge of the canvas, the right boundary of the right subplots is 1 character width from the canvas edge. The overall bottom margin is one character height and the overall top margin is 2 character heights. There is no horizontal gap between the two columns of subplots. The vertical gap between subplots is equal to 2 character heights.

Example:

     set multiplot layout 2,2 columnsfirst margins 0.1,0.9,0.1,0.9 spacing 0.1
     set ylabel 'ylabel'
     plot sin(x)
     set xlabel 'xlabel'
     plot cos(x)
     unset ylabel
     unset xlabel
     plot sin(2*x)
     set xlabel 'xlabel'
     plot cos(2*x)
     unset multiplot

See also http://www.gnuplot.info/demo/multiplt.htmlmultiplot demo (multiplt.dem)