I want to insert a plot into another overlay plot. Here is my code:
xy1 = Table[{i, 2*i}, {i, 1, 10}];
xy2 = Table[{i, i^2}, {i, 1, 10}];
xy3 = Table[{i, i^3}, {i, 1, 10}];
p1 = ListPlot[xy1, FrameLabel -> {"x", "2x"},
PlotStyle -> {Directive[Red, Dashed], Red},
Frame -> {True, True, True, False}, ImagePadding -> 40,
FrameStyle -> {Automatic, Red, Automatic, Automatic},
PlotMarkers -> {\[FilledCircle]}, Joined -> True, PlotRange -> All];
p2 = ListPlot[xy2, FrameLabel -> {"x", "", "", "x^2"},
PlotStyle -> Blue, Frame -> {False, False, False, True},
ImagePadding -> 40,
FrameStyle -> {Automatic, Automatic, Automatic, Blue},
FrameTicks -> {None, None, None, All},
PlotMarkers -> \[FilledUpTriangle], Joined -> True,
PlotRange -> All];
p3 = ListPlot[xy3, FrameLabel -> {"x", "x^3"}, PlotStyle -> Green,
Frame -> {True, True, True, True}, PlotMarkers -> \[EmptyCircle],
Joined -> True, PlotRange -> All]
p12 = Overlay[{p1, p2}]
p123 = Graphics[{p12, Inset[p3]}]
p1232 = Graphics[{Rectangle[{0, 0}, {2, 2}, p12],
Rectangle[{0.3, 0.25}, {0.9, 0.9}, p3]}]
p1233 = Graphics[{First[p12],
Inset[p3, {5, 20}, Automatic, Scaled[.8]]}, PlotRange -> All,
AbsoluteOptions[p12]]
p12 is the overlay plot of p1 and p2, having two y axes. I want to insert p3 into p12.
I have read this post: How to insert a plot into another plot
And tried three ways to do the job, with the result figure represented as p123, p1232, and p1233 respectively. However, none of p123, p1232, and p1233 is successful:
p123:
p1232:
p1233:
Among them p123 and p1233 caused errors. P1232 is close to what I want, but still is very weird. I want to insert p3 into the blank area of p12. Can anyone please help?
Graphics
they are anOverlayBox
so this is why your code is failing. You can overlay more than two items so maybe that might be your best option. $\endgroup$