# Keeping the same scale but a different range of horizontal axes of two plots in a grid

We have two plots.

g1 = Plot[{1 - 2 x, 1 - x}, {x, 0, 2}, PlotRange -> {0, 2}];
g2 = Plot[ 1 - 2 x,         {x, 0, 2}, PlotRange -> {0, 2}];
Grid[{
{g1, g2}
}]


This gives something like: What I need is something like the following (same scale but different range of horisontal axes): It is important to keep the same plot Range. And it would be nice to have it automatically, not playing manually with inches. Grid is not obligatory if there is more convenient way.

That sort of graphics often arises in economics when so called 'horizontal summation' takes place, i.e. demand function in essence is of the form x[y] in normal terms.

You can add AspectRatio -> Automatic, ImageSize -> {Automatic, height} for both plots:

opts = {PlotRange -> {0, 2}, AspectRatio -> Automatic,
ImageSize -> {Automatic, 200}};
g1 = Plot[{1 - 2 x, 1 - x}, {x, 0, 2}, Evaluate@opts];
g2 = Plot[1 - 2 x, {x, 0, 1}, Evaluate@opts];
Grid[{{g1, g2}}] Then one can play around with ticks.

• Oh, AspectRatio -> Automatic. How did I miss that. – Edmund Nov 15 '15 at 14:32
• @Edmund It simple to miss because here the default value is not Automatic. – ybeltukov Nov 15 '15 at 15:18

The AspectRatio is determining the size of the axis in the plots. These can be set for each plot along with the ImageSize for the results you are seeking. Also, the PlotRange needs to set the x-axis separate from the y-axis for the second plot.

AspectRatio is a $\frac{\text{height}}{\text{width}}$ ratio so for the first plot we need $\frac{2}{2}$ and for the second we need $\frac{2}{1}$. For ImageSize we only need to match the heights since the AspectRatio will take care of the widths. Finally, the PlotRange of the second plot is set so that it matches the AspectRatio to the scale desired. Here the scale is 1:1 for these.

g1 = Plot[{1 - 2 x, 1 - x}, {x, 0, 2}, PlotRange -> {0, 2},
AspectRatio -> 1, ImageSize -> {Automatic, 200}];
g2 = Plot[1 - 2 x, {x, 0, 2}, PlotRange -> {{0, 1}, {0, 2}},
AspectRatio -> 2, ImageSize -> {Automatic, 200}];
Grid[{{g1, g2}}] The ticks on the second plot are a bit bunched but can be set with Ticks if needed.

xticks = If[Mod[#, .5] == 0, {#, ToString@#, .04}, {#, ""}] & /@
Range[0, 2, 0.1]

g1 = Plot[{1 - 2 x, 1 - x}, {x, 0, 2}, PlotRange -> {0, 2},
Ticks -> {xticks, Automatic},
AspectRatio -> 1, ImageSize -> {Automatic, 200}];
g2 = Plot[1 - 2 x, {x, 0, 2}, PlotRange -> {{0, 1}, {0, 2}},
AspectRatio -> 2,
Ticks -> {xticks, Automatic}, ImageSize -> {Automatic, 200}];
Grid[{{g1, g2}}] You can also use GraphicsGrid instead of Grid.

• why are 'main' ticks on the right plot shorter than on the left? – garej Nov 15 '15 at 16:34
• it seems like AspectRatio influences ticks marks size... – garej Nov 15 '15 at 16:51
• @garej Tick mark size is uses Scaled by default and this is a function of the width of the graphic. I was trying to get the labeled ticks higher than the unlabeled ones. You don't have to specify tick size. – Edmund Nov 15 '15 at 18:36

Overlay second plot with white Rectangle

g1 =
Plot[
{1 - 2 x, 1 - x}, {x, 0, 2},
GridLines -> Automatic,
ImageSize -> 400,
PlotLegends -> Placed["Expressions", Above],
PlotRange -> {0, 2}];

g2 =
Plot[1 - 2 x, {x, 0, 2},
Epilog -> {White, Rectangle[{1., -0.1}, {2, 2.1}]},
GridLines -> {{0.5, 1}, Automatic},
ImageSize -> 400,
PlotRange -> {0, 2},
Ticks -> {Transpose[{#, PaddedForm[#, {2, 1}] & /@ #}] &[{0., 0.5, 1.}], Automatic}];

Grid[{{g1, g2}}] 