Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to put an inset on top of a graph, the inset is also a graph. I'm using Inset within Epilog and the following command line:

Epilog -> {Inset[coherenceLengthGraph, {12, 0.35}, {Automatic, Top}, 11]}

I've tried many things yet I cannot put the inset above the base graph.

I'm using Show to render two lists of different data on the same graph, after that -and within Show- I use Epilog. I looked at GraphicsColumn but I couldn't see how it allows things that one can do using Inset.

Here's my code

 pwaveGraph = Show[graphlistofKPPhaseBoundaries, graphKPBands,
   Frame -> {True},
   FrameLabel -> {"2μm/\!\(\*SuperscriptBox[\(\[HBar]\), \
\(2\)]\)", "" }, PlotRange -> {{-2, 18.05}, {-1.05, 1.05}},
   FrameTicks -> {Automatic, {-1, 0, 1}}, 
   Epilog -> {Inset[
      coherenceLengthGraph, {12, 0.35}, {Automatic, Top}, 11]}];
share|improve this question
If you want it to be strictly above the base graph, and not overlapping with it, why don't you use Column instead of Inset? Also, please provide some more information about what you are doing. Epilog is not an option for Graph (it works in Show and Graphcis though) – Szabolcs Dec 2 '12 at 19:58
I realise you were talking about graphics, not graphs (as in networks). Column/GraphicsColumn should still be useful. Can you please try it? – Szabolcs Dec 2 '12 at 20:06
Welcome to Mathematica.SE! Please consider registering your account so that any upvotes you get on this question are added to those you might get on future questions and answers. That way, over time you will be able to do more on the site (post graphics, edit things, etc). – Sjoerd C. de Vries Dec 2 '12 at 20:13
@AykutTeker Please add your code into your question as an edit rather than squeezing it into a comment, where it is all but unreadable. – m_goldberg Dec 2 '12 at 22:08

Here is a solution that stays with the approach you started:

p = Plot[Sin[x], {x, 0, 2 Pi}, Background -> Lighter[Orange]];

With[{insetWidth = Pi, insetHeight = 1.6, extraPixels = 120},
 Plot[Cos[x], {x, 0, 2 Pi},
  Epilog -> Inset[p,
    {Pi, insetHeight},
    {Automatic, Automatic},
  ImagePadding -> {{Automatic, Automatic}, {Automatic, extraPixels}}, 
  PlotRangeClipping -> False]

pic inset

I added ImagePadding and suppressed PlotRangeClipping.

share|improve this answer

Exact Inset positioning sometimes requires a bit of trial and error. Here is a variation of @Jens approach using Locator

p = Plot[Sin[x], {x, 0, 2 Pi}, Background -> Lighter[Orange]];
extraPixels = 120;
pt = ImageScaled[{0.5, 0.8}];

plot = Plot[Cos[x], {x, 0, 2 Pi}, 
  Epilog -> Dynamic@Locator[Dynamic@pt, p, LocatorRegion -> Full],
  ImageSize -> {400, 300 + extraPixels}, AspectRatio -> 3/4, 
  ImagePadding -> {{Automatic, Automatic}, {Automatic, extraPixels}}, 
  PlotRangeClipping -> False, Frame -> True]

For repeat plots you can now get the locator coordinates and use them from now on in an inset

coords = First@
   Cases[plot /. Dynamic -> Identity, x_ImageScaled, \[Infinity]];

Plot[Cos[x], {x, 0, 2 Pi}, Epilog -> Inset[inset, coords],
 ImageSize -> {400, 300 + extraPixels}, AspectRatio -> 3/4, 
 ImagePadding -> {{Automatic, Automatic}, {Automatic, extraPixels}}, 
 PlotRangeClipping -> False, Frame -> True]
share|improve this answer

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.