3
$\begingroup$

I have generated a plot and subplot fine, and I would like to position it in the top right corner of the main plot. Ordinarily I would use the position options. However, my notebook is used for processing multiple data sets and the axes change, so I can't position the subplot using coordinates of the main plot.

Could I use pixels or the size of the main plot or get the maximum values on the x- and y-axis for the positioning?

$\endgroup$
5
$\begingroup$

Here's an example with Scaled coordinates:

SetOptions[Plot, Frame -> True, Axes -> False];

mainplot = Plot[Exp[x], {x, -3, 3}]

subplot = Plot[Sin[x], {x, 0, 3}]

Show[mainplot, 
 Epilog -> Inset[subplot, Scaled[{1, 1}], Scaled[{1, 1}]]]

Returns

enter image description here

Check the documentation of Inset for details

$\endgroup$
  • $\begingroup$ Perfect! Different approach to what I was using! $\endgroup$ – QuantumPenguin Mar 17 '15 at 11:49
  • $\begingroup$ Glad to help. The next step (in my example) would be to fiddle around with PlotRange and/or Background to prevent the unsightly overlap of Exp[x] over the inset, but that's moving beyond the scope of the question. $\endgroup$ – LLlAMnYP Mar 17 '15 at 11:56
  • $\begingroup$ Yeah that's fine, I altered the FrameTicks to compensate. It's a good solution you have posted. Before I was just using a listlineplot with epilog and a second listlineplot positioned based on the coordiantes of the main plot which is a hopeless way of doing things! $\endgroup$ – QuantumPenguin Mar 17 '15 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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