2
$\begingroup$

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]}];
$\endgroup$
4
  • 1
    $\begingroup$ 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) $\endgroup$
    – Szabolcs
    Dec 2, 2012 at 19:58
  • $\begingroup$ I realise you were talking about graphics, not graphs (as in networks). Column/GraphicsColumn should still be useful. Can you please try it? $\endgroup$
    – Szabolcs
    Dec 2, 2012 at 20:06
  • $\begingroup$ 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). $\endgroup$ Dec 2, 2012 at 20:13
  • 2
    $\begingroup$ @AykutTeker Please add your code into your question as an edit rather than squeezing it into a comment, where it is all but unreadable. $\endgroup$
    – m_goldberg
    Dec 2, 2012 at 22:08

2 Answers 2

2
$\begingroup$

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},
    insetWidth
    ],
  ImagePadding -> {{Automatic, Automatic}, {Automatic, extraPixels}}, 
  PlotRangeClipping -> False]
 ]

pic inset

I added ImagePadding and suppressed PlotRangeClipping.

$\endgroup$
0
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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