- not so Frequently Asked Questions -

update 2004/9/5

About 2-Dimensional Plot (No.6)


Align two figures those show the same data in a different way.

Here we present a method to align two figures vertically or horizontally, those are essentially the same data but in a different appearance. You probably need such a figure in the next cases.

  • Place two figures in a different scale.
    • When you want to enlarge a certain X-range. For example, you want to magnify the small X region and plot the data there with a log-scale, and the other part is in a linear scale.
  • Compare two similar data with each other by absolute values and ratio.
    • When you are plotting two different data whose Y values are very close each other, you are probably very hard to distinguish two lines. If you want to show the fact that those two data are very similar, such a figure might be OK. However, if you want to show the similarity of those data quantitatively, you can calculate a ratio of one data to the other, and plot them to show the deviation from ratio=1. We divide one figure into two parts, and plot a comparison of the absolute values in the upper potion, and the lower is the ratio of them.


Place two figures in a different scale.


Here is an example data. This figure shows the X-range of [0:30], but the data near X=0 are also important, and you want to show there in detail. Of course you can make two figures in a different scale, but we combine those two. Firstly we plot the data below 1 in the log-scale.

gnuplot> set log xy
gnuplot> set xrange [ 0.001 : 1 ]
gnuplot> set yrange [ 0.1 : 5000 ]
gnuplot> set xlabel "Energy [eV]"

For the data in [1:30] we use the linear-scale plot, and we place this adjacent to the log-scale figure by using multiplot . In order to adhere the high-X region figure (right side) to the low-X (left side), we let the rmargin of left figure be zero, and lmargin of the right side is also zero. The width of those two figure is a half of full-width, then the right side figure is sifted by 0.5 by using set origin .

We need the Y-tics for the left side figure, but we don't need it for the right side. So that set lmargin 10 is defined for the left, while lmargin is zero for the right. In addition, set format "" erases Y-axis values.

gnuplot> set multiplot
multiplot> set size 0.5,1
multiplot> set origin 0.0,0.0
multiplot> set lmargin 10
multiplot> set rmargin 0
multiplot> plot "calc.dat" u 1:2 w l
multiplot> set origin 0.5,0.0
multiplot> set format y ""
multiplot> set lmargin 0
multiplot> set rmargin 2
multiplot> set nolog x
multiplot> set xrange [1:30]
multiplot> set xtic 0,10
multiplot> set mxtic 5
multiplot> plot "calc.dat" u 1:2 w l
multiplot> set nomultiplot

You have to say clearly that the figures on the left and right are in the different scale. To do this we put minor tics on the X-axis. At the border between two drawings, sometimes X-axis numbers are overlapped. The command set xtics 0,10(initial value 0, increment 10) avoids the tics at X=1.

By the way, we know that this example data become linear in a log-log scale at small X-values, because this is some physical quantity. It is possible to demonstrate such a characteristic very easily if you divide one figure into two regions.

In this example the X-axis name is drawn twice, but you can make it one in the middle of the whole figure. For the left side, you erase the axis name by set xlabel "", and move the label on the right side by set xlabel "Energy [eV]" -20,0. In this case you need to set bmargin 5 to fix the bottom margin.



If you want to compare two sets of data those are very close, it is useful that those data are plotted absolutely, and the ratio of those data are given at the same time. The comparison of absolute values are in the log-scale which goes upper part, while the ratio is in the linear-scale shown in the lower part.

In order to calculate the ratio of one data to another, the X values of those data should be the same. In our data file, the first column contains the X value, the second column is the Y value of the first data set, and the third column is the Y of second set.

Firstly we set some X-axis parameters those are common to the upper and lower figures. The X range is [0.01:30]. To make the width of those figures be the same, we define margins of left and right sides explicitly.

gnuplot> set xrange [ 0.01 : 30 ]
gnuplot> set nokey
gnuplot> set log x
gnuplot> set xtics 10
gnuplot> set mxtics 10
gnuplot> set lmargin 10
gnuplot> set rmargin 2

Make the lower part which shows the ratio data. The hight is reduced to 0.4, the Y-range is from 0.5 to 1.5, and put the graduations from 0.6 to 1.4 with the interval of 0.2. To make a space of the X-axis name, use set bmargin, and to attach the upper part, set tmargin 0 removes the extra-space above. The Y values of two data sets are in the second and third column of the data file. To plot the ratio of the first data to the second ones, plot 1:($2/$3). In addition, a straight line of Y=1 is helpful to show the ratio data.

gnuplot> set multiplot
multiplot> set yrange [ 0.5 : 1.5 ]
multiplot> set ytic 0.6,0.2,1.4
multiplot> set ylabel "Ratio"
multiplot> set size 1,0.4
multiplot> set xlabel "Energy [eV]"
multiplot> set origin 0.0,0.0
multiplot> set bmargin 3
multiplot> set tmargin 0
multiplot> plot 1 w l 0,"cross.dat" u 1:($2/$3) w l 1

Now we make the upper part. Make the size smaller, move the origin to the left-top corner of the lower part. The two data sets are shown in the log-scale. set bmargin 0 removes the extra-space below. The X-axis name and numbers should be erased.

multiplot> set log xy
multiplot> set yrange [ 0.1 : 5000 ]
multiplot> set ytic 0.1,10
multiplot> set ylabel "Cross Section [b]"
multiplot> set size 1,0.6
multiplot> set origin 0.0,0.4
multiplot> set bmargin 0
multiplot> set tmargin 1
multiplot> set format x ""
multiplot> set xlabel ""
multiplot> plot "cross.dat" u 1:2 w l,"" u 1:3 w l
multiplot> set nomultiplot

Since we erased the legend in this example, it is not easy to understand that the ratio shown here is A to B, or B to A. If you see the upper figure, you might recognize that this is the ratio of red curve to the green curve, because the red is lower than the green. However such a statement should be given in a caption of this figure.

You can see an example of EPS in our gallery.