# Combining two plots at a common x-axis

I want to combine a Plot and a ListPlot at their common x-axis. Here's an example of what I've got so far:

fgraph = Plot[1 - x^2
- 0.5654788166963185 E^(-2.25 (-0.2 + x)^2)
- 0.5654788166963185 E^(-2.25 (0.2 + x)^2), {x, -1, 1},
AxesOrigin -> {-1, 0}];
ggraph = ListPlot[
{{{-0.2, 0}, {-0.2, 0.5}}, {{0.2, 0}, {0.2, 0.35}}},
Joined -> True, PlotRange -> {{-1, 1}, {0, All}},
AxesOrigin -> {1, 0}];
GraphicsColumn[{ggraph, fgraph}, Automatic, -112]


It looks pretty close to what I want, but there are a few problems:

1. The x-axes are not on the exact same horizontal scale, so they don't line up perfectly,
2. The spacing of -112 in GraphicsColumn had to be found manually and it's not quite right either, and
3. I'd like to be able to adjust the top plot's AspectRatio to make it around half the current height.

The solution needs to be automated since this is only an example.

Note that I need to keep the two different scales for the y-axis, since the y-axes in fgraph and ggraph are measured in different units and may be orders of magnitude different. This problem seems similar to 1 Plot, 2 Scale/Axis but different since I want the same x-axis at y==0.

• Use Show Show[ggraph, fgraph, PlotRange -> All, AxesOrigin -> {0, 0}] – Bob Hanlon May 20 '19 at 14:07
• @BobHanlon That's easy and looks OK in this example, but I need to keep the two different scales for the y-axis since the y-axes in fgraph and ggraph are measured in different units and may be orders of magnitude different. I'll clarify my question. – Chris K May 20 '19 at 14:11

I'll also use kglr's approach (in his deleted answer) of insetting the list plot into the Plot output. The one tricky part is that the entire list plot, both plot range and image padding, gets inserted. This means that if the object has any image padding, it will be shrunk when it is placed into the Plot output. This is what happened in kglr's deleted answer.

The trick, then, is to eliminate the image padding, and make sure that Plot uses the same plot range, which almost works:

fgraph = Plot[
1-x^2-0.5654788166963185 E^(-2.25 (-0.2+x)^2)-0.5654788166963185 E^(-2.25 (0.2+x)^2),
{x,-1,1},
AxesOrigin->{-1,0},
PlotRange -> {{-1, 1}, Automatic} (* same plot range *)
];
ggraph=ListPlot[
{{{-0.2,0},{-0.2,0.5}},{{0.2,0},{0.2,0.35}}},
Joined->True,
PlotRange->{{-1,1},{0,All}},
AxesOrigin->{1,0},
AspectRatio -> 1/4, (* adjust aspect ratio *)
];

Show[fgraph, Epilog -> Inset[ggraph, {1, 0}, {1, 0}, Scaled[1]]]


Note that the horizontal axis matches perfectly now. The main issue is that setting ImagePadding to 0 caused the list plots vertical axis to disappear. One simple remedy is to increase the plot range to include the vertical axis:

fgraph = Plot[
1-x^2-0.5654788166963185 E^(-2.25 (-0.2+x)^2)-0.5654788166963185 E^(-2.25 (0.2+x)^2),
{x,-1,1},
AxesOrigin->{-1,0},
PlotRange -> {{-1, 1.05}, Automatic} (* same plot range *)
];
ggraph=ListPlot[
{{{-0.2,0},{-0.2,0.5}},{{0.2,0},{0.2,0.35}}},
Joined->True,
PlotRange->{{-1,1.05},{0,All}},
AxesOrigin->{1,0},
AspectRatio -> 1/4, (* adjust aspect ratio *)

• Not to gild the lily, but would it be possible to do the same with Frame -> {{False, True}, {False, False}} on ggraph, to put the right side's ticks and labels outside the graph? I haven't been able to get that working. – Chris K May 20 '19 at 17:23