Andrei Tudor
Andrei Tudor

Reputation: 45

Gnuplot: Multiplot size and scaling of one plot

I have this multiplot:

enter image description here

Generated by the following code:

set terminal pdf size 15,10
set output "graph.pdf"
set key off
set multiplot layout 5, 1 scale 1, 1
set style data histograms
set style histogram
set style fill solid border -1
set boxwidth 0.75
set yrange [0:178]
set ytics 50
set xtics offset 0,graph 0.01
set xtics font ",20"
set x2tics font ",20"
set ytics font ",20"
set tmargin 3
set bmargin 3
set style line 1 linetype -1 linewidth 3
set grid mxtics
set xtics (0.5 1,1.5 1,2.5 1,3.5 1,4.5 1,5.5 1,6.5 1,7.5 1,8.5 1,9.5 1,10.5 1,11.5 1,12.5 1,13.5 1,14.5 1,15.5 1,16.5 1,17.5 1,18.5 1,19.5 1,20.5 1,21.5 1,22.5 1,23.5 1,24.5 1,25.5 1,26.5 1,27.5 1,28.5 1,29.5 1,30.5 1 )
set tics out

plot 'outil1' every ::0::30 u 7:xtic(2) notitle lt rgb "blue" fillstyle pattern 2, 'ppm' every ::0::30 u 7 notitle lt rgb "red" fillstyle pattern 2, \
newhistogram at 0, 'outil1' every ::0::30 u 6:x2tic(1) notitle lt rgb "blue", 'ppm' every ::0::30 u 6 notitle lt rgb "red"
plot 'outil1' every ::30::60 u 7:xtic(2) notitle lt rgb "blue" fillstyle pattern 2, 'ppm' every ::30::60 u 7 notitle lt rgb "red" fillstyle pattern 2, \
newhistogram at 0, 'outil1' every ::30::60 u 6:x2tic(1) notitle lt rgb "blue", 'ppm' every ::30::60 u 6 notitle lt rgb "red"
plot 'outil1' every ::60::90 u 7:xtic(2) notitle lt rgb "blue" fillstyle pattern 2, 'ppm' every ::60::90 u 7 notitle lt rgb "red" fillstyle pattern 2, \
newhistogram at 0, 'outil1' every ::60::90 u 6:x2tic(1) notitle lt rgb "blue", 'ppm' every ::60::90 u 6 notitle lt rgb "red"
plot 'outil1' every ::90::120 u 7:xtic(2) notitle lt rgb "blue" fillstyle pattern 2, 'ppm' every ::90::120 u 7 notitle lt rgb "red" fillstyle pattern 2, \
newhistogram at 0, 'outil1' every ::90::120 u 6:x2tic(1) notitle lt rgb "blue", 'ppm' every ::90::120 u 6 notitle lt rgb "red"
plot 'outil1' every ::120::150 u 7:xtic(2) notitle lt rgb "blue" fillstyle pattern 2, 'ppm' every ::120::150 u 7 notitle lt rgb "red" fillstyle pattern 2, \
newhistogram at 0, 'outil1' every ::120::150 u 6:x2tic(1) notitle lt rgb "blue", 'ppm' every ::120::150 u 6 notitle lt rgb "red"

To generate the plot you need outil1 data file and ppm data file

The problem that I have with this is the plot is that the last one is not equal in size with the first 4 plots. The distance between the tics is bigger in the last plot in order to make it fit the entire canvas.

Is there a way to make the last plot aligned with the other? For example have the 126 tic align with the 96 tic from the 4th plot.

Thank you.

Upvotes: 2

Views: 1616

Answers (1)

Christoph
Christoph

Reputation: 48390

After you have plotted the four graph, you can fix the left margin to the value it has at this momen, and adapt the right margin according to the different scales from graph four to graph five.

You can calculate the left margin in screen coordinates (i.e. in the range [0:1], with 0 beeing the leftmost canvas edge and 1 the rightmost canvas edge) as follows:

LMARGIN = GPVAL_TERM_SCALE * (0.0 + GPVAL_TERM_XMIN)/GPVAL_TERM_XSIZE

Here, GPVAL_TERM_SCALE is a factor, which is available only in gnuplot 5, but is required to get the correct calculations independent on the used terminal. When using gnuplot 4.6. and the pdfcairo terminal, this value is 20. You can put a small if-clause in the script to check this:

if (exists('GPVAL_TERM_SCALE')) SCALE = GPVAL_TERM_SCALE; else SCALE = 20

So, the last plot command in your script should look as follows:

if (exists('GPVAL_TERM_SCALE')) SCALE = GPVAL_TERM_SCALE; else SCALE = 20
LMARGIN = SCALE * (0.0 + GPVAL_TERM_XMIN)/GPVAL_TERM_XSIZE
RMARGIN = SCALE * (0.0 + GPVAL_TERM_XMAX)/GPVAL_TERM_XSIZE

set lmargin screen LMARGIN
set rmargin screen LMARGIN + (17.0/32.0)*(RMARGIN - LMARGIN)

plot 'outil1' every ::120::150 u 7:xtic(2) notitle lt rgb "blue" fillstyle pattern 2, 'ppm' every ::120::150 u 7 notitle lt rgb "red" fillstyle pattern 2, \
newhistogram at 0, 'outil1' every ::120::150 u 6:x2tic(1) notitle lt rgb "blue", 'ppm' every ::120::150 u 6 notitle lt rgb "red"

I got the factor (17.0/32.0) just by manually counting the ranges you want to plot. The result is

enter image description here

Upvotes: 2

Related Questions