Preparing figures with multiple plots is very easy with Gnuplot. First one has to specify a size of the whole figure and then enter the multiplot mode. After that every single component of the total figure is done using the usual
plot
function. However, every component has to be preceded by definition of its size and origin with respect to the full page (specified before entering the multiplot mode). Let us consider an example when we need to prepare a figure with 5 smaller plots. Figure 1 shows the desired structure of the plot.
We begin with specifying the size of the page with height equal 4 and width equal 5. After that we enter the muliplot mode.
set size 5.0,4.0 set multiplot
One has to remember that all parameters after setting are carried down the script until the parameter is changed. In this example I will plot the same function in all parts of the plot so the labels and ranges and tics for axes may be specified only once at the beginning.
set xlabel "x" set ylabel "y" set ytics 0.5
After that we may proceed with plotting individual components remembering that we need to manually change all parameter that differ for individual plots. Every plot has to be started with definition of the size and origin.
# plot A set origin 0.0,2.0 set size 2.0,2.0 plot sin(x) ls 1
All other components may be plotted in the same way changing the origin and adjusting the size of the plot. Plot displayed on the scheme in Figure 1 may be done using the following script.
#!/usr/bin/gnuplot set terminal postscript eps enhanced color "Helvetica" 50 set output "results.eps" set style line 1 lt 1 lw 15 pt 5 ps 1 lc rgb "#d61818" set style line 2 lt 2 lw 15 pt 9 ps 1 lc rgb "#072c76" set style line 3 lt 3 lw 15 pt 9 ps 1 lc rgb "#072c76" set style line 4 lt 4 lw 15 pt 7 ps 1 lc rgb "#208418" set style line 5 lt 5 lw 15 pt 11 ps 1 lc rgb "#d97c19" set size 5.0,4.0 set multiplot set xlabel "x" set ylabel "y" set ytics 0.5 # plot A set origin 0.0,2.0 set size 2.0,2.0 plot sin(x) ls 1 # plot B set origin 0.0,1.0 set size 2.0,1.0 plot sin(x) ls 2 # plot C set origin 0.0,0.0 set size 3.0,1.0 plot sin(x) ls 3 # plot D set origin 2.0,1.0 set size 3.0,3.0 plot sin(x) ls 4 # plot E set origin 3.0,0.0 set size 2.0,1.0 plot sin(x) ls 5The result of the script should look as follows.
Figure 2. Gnuplot generated figure based on the scheme from the figure above and presented script. |
Doesn't work with gnuplot 4.6 pl3 (Cygwin) with PNG output: each plot overwrites the last plot and in the end I see only one sine which covers the full canvas.
ReplyDeleteI agree with first "Anonymous". If you copy the code and change terminal to pngcairo and output to .png, it doesn't works well.
ReplyDeleteThis is best used, when plotting in .pdf or eps. I personally think, if you are using gnuplot for plots, make the habit of using the EPS or PDF terminals to plots the figures. They look much much better in documents and looks quite nice to the eye and above all, they are vectorial. So no distortion in the plot if you zoom or stretch. PNG terminal does not produce nice plots, in my opinion. This is good for a quick look, but not for the final product.
ReplyDeleteMany thanks for the writer of the Blog for being very methodical in teaching us how this is done. It really helped me a lot in my problem when producing plots for my thesis. Well done !
This doesn't work for terminal x11. gnuplot 5.2 patchlevel 7
ReplyDeleteNormally, I wouldn't waste anyone's time with a comment such as this, but I really need to understand this, and the documentation seems to be written for someone who already knows how to do it.
origin and size must now be scaled to 1
ReplyDeleteFirst line: set size 5.0,4.0
plot all the way to the left and in the middle:
set origin 0,0.5 instead of set origin 0, 2.0
Excellent explanation, thank you!
ReplyDeleteWow! thank you, this worked perfect cut and paste on my rpi400. What I am trying to do is get 'results.eps' output to the screen. Solutions?
ReplyDeleteCool and I have a super give: How Much Is House Renovation Loan In Pag Ibig small home renovation contractors
ReplyDelete