I basically want to have share the x axis in three plots in a multiplot.
Here is the code:
set terminal wxt enhanced size 480,288 dashed;
#Header end
set multiplot;
set size 1,0.4;
set origin 0,0;
set xlabel "x";
set ylabel "y1";
set ytics 200;
set key off;
plot '-' u 1:2:xtic(3) w points, '-' w points;
1 851 1
2 663 4
3 367 8
4 368 9
e
1 829 1
2 646 4
3 354 8
4 359 9
e
set xlabel "";
set format x "";
set size 1,0.3;
set origin 0,0.4;
set ylabel "y2";
set ytics 0.6;
plot '-' w points, '-' w points;
1 1.633468456
2 1.113943352
3 1.361727836
4 1.643452676
e
1 1.447158031
2 1.380211242
3 1.414973348
4 1.643452676
e
set size 1,0.3;
set origin 0,0.7;
set ylabel "y3";
set ytics 1000;
plot '-' w points, '-' w points;
1 3317
2 1567
3 846
4 895
e
1 3342
2 1612
3 978
4 1101
e
unset multiplot
Here is the current figure:
I want to adjust the x axes in this multiplot to have the same length, so that the three plots can share the x axis.
Update:
After adding "set lmargin at screen 0.2;" in the beginning of the code, I have the following:
It is close to what I want but the three y labels are not aligned anymore: y2 is not in line with y1 and y3. How can I ensure that the labels are aligned?
This can be achieved simply by explicitly setting the left margin. The right one is aligned by default.
By adding set lmargin at screen 0.1
, you can obtain the following:
You can also tweak the top and bottom margins of each plot if you like, to join together the plots like this:
To achieve this I used set bmargin 0.05; set tmargin 0.35
for the first plot, then set bmargin 0.35
for the second, etc. I also adjusted the yrange
to prevent the ytics
from overlapping too much. Adjust to taste! :)
As you've pointed out, the lmargin
value also affects the positioning of the ylabel
. To deal with this, you have a few options:
set format y "%.1e"
to ensure that the format is consistent for each graph. By enforcing a fixed number of decimal places, the ylabel
s will all be aligned.set ylabel offset
to shift the labels into place. Don't forget that the offset will be applied to all subsequent ylabel
s, so if you want to shift the middle one but not the last, you need to explicitly reset the offset to 0
on the last one.ylabel
at all, just use set label at screen X,Y rotate by 90
, where X
is fixed and Y
is will differ for each plot. This gives you maximum flexibility over the positioning of the labels.