3

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:

plot, x axes different lengths

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:

plot, x axes same length

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?

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
Changwang Zhang
  • 2,467
  • 7
  • 38
  • 64

1 Answers1

3

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:

plots with equal left margins

You can also tweak the top and bottom margins of each plot if you like, to join together the plots like this:

plots joined together by adjusting top and bottom margins

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:

  1. Use something like set format y "%.1e" to ensure that the format is consistent for each graph. By enforcing a fixed number of decimal places, the ylabels will all be aligned.
  2. Use set ylabel offset to shift the labels into place. Don't forget that the offset will be applied to all subsequent ylabels, 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.
  3. Instead of using 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.
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • 1
    Thanks for the answer, but after using "set lmargin at screen 0.2;" the three y labels are not aligned anymore. Please see my second figure. – Changwang Zhang Aug 08 '14 at 11:47
  • 2
    There are some ways you can get around this problem. I have added some suggestions to my answer. Hope that helps. – Tom Fenech Aug 08 '14 at 12:09
  • 1
    If you use `set ylabel offset` you must specify a value in all three cases: `set ylabel 'y1'; ...; set ylabel 'y2' offset -1; ...; set ylabel 'y3' offset 0`. Otherwise the last label would retain the changed offset of the previous set. – Christoph Aug 08 '14 at 12:23