Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to know whether there is a way to insert a plot into another plot. I would like to do some plot from a function an then, inside this plot, in the right down corner add a smaller plot of the same function covering a smaller region. I tried with Epilog but it's not possible that way, it gives me a fail

Thanks in advance!

share|improve this question
You've seen Inset[]? –  J. M. Nov 14 '12 at 9:54
add comment

4 Answers

...or do it dynamically so you can position the inset where you like it:

DynamicModule[{pt = Scaled[{0.5, 0.5}]},

 Plot[Sin[x], {x, 0, 2 Pi},
  PlotRange -> All, 
  Epilog -> {Dynamic[
      Plot[Cos[x], {x, 0, 2 Pi}, Background -> White, 
       ImageSize -> 150]]]}]]

enter image description here

share|improve this answer
1+ I liked this Dynamic tip! Cool! –  Murta Nov 14 '12 at 13:53
add comment

You can use Inset for this

Building a new Graphics

gr1 = Plot[Sin[x]^2, {x, 0, 6 Pi}];
gr2 = Plot[Sin[x]^2, {x, 0, Pi}];

Graphics[{First[gr1], Inset[gr2, {15, -.6}, Automatic, Scaled[.4]]}, 
 PlotRange -> {Automatic, {-1, 1}}, AbsoluteOptions[gr1]]

Mathematica graphics

Using Epilog

Plot[Sin[x]^2, {x, 0, 6 Pi}, PlotRange -> {Automatic, {-1, 1}}, 
 Epilog -> {Inset[gr2, {15, -.6}, Automatic, Scaled[.4]]}]
share|improve this answer
Ha Yep, question solved! That's what I was looking for! And with Background->White option it covers the old plot if necessary! Thanks a lot! –  pablo Nov 14 '12 at 10:02
Thank's to ! ;) –  pablo Nov 14 '12 at 10:03
add comment

You mean something like this?

p1 = Plot[Sin[x], {x, 0, 2 π}];
p2 = Plot[Sin[x], {x, 0, π}];

Show[Graphics[{Rectangle[{0, 0}, {1, 1}, p1], 
  Rectangle[{0.7, 0.4}, {1, 1}, p2]}]]

enter image description here

share|improve this answer
This was how it was done before Inset[] came along... –  J. M. Nov 14 '12 at 9:56
@J.M. Ha, it means that it is a long time that I didn't have the need to do something like this. –  VLC Nov 14 '12 at 9:57
(+1) very nice. I don't think i have seen this syntax before; any references? –  kguler Nov 14 '12 at 10:02
@kguler, it was documented in old versions; apparently, when Inset[] became available in version 6, that piece of syntax was quietly redacted. –  J. M. Nov 14 '12 at 10:28
@J.M. thank you. –  kguler Nov 14 '12 at 10:32
show 1 more comment

In addition to Inset etc., you can do this manually with the 2D Graphics editing tools.

First producing plots as halirutan did:

p1 = Plot[Sin[x], {x, 0, 2 π}]
p2 = Plot[Sin[x], {x, 0, π}]

Mathematica graphics

Click the first one to select it (orange border):

Mathematica graphics

Then Copy or Cut the object.

Next, double-click the second graphic to enter editing mode (gray border):

Mathematica graphics

And Paste the first graphic:

Mathematica graphics

You can then position and resize the inset graphic using the orange frame.
When you are done just click outside of the main gray frame.

share|improve this answer
Even easier, thanks a lot! –  pablo Nov 14 '12 at 11:25
This is a good solution, but in the end I would like to have a code from where I can re-run if I want those specifications again. Any simple way of retrieving that information? –  J. C. Leitão Dec 27 '12 at 13:37
@J.C.Leitão Sorry, I never saw your comment. I can't think of anything practical but that could be a good question; why don't you post it? (If you haven't done so already in the long time since you asked this.) –  Mr.Wizard Aug 14 '13 at 22:54
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.