1
$\begingroup$

I would like to modify an existing code to add two Insets to the same image, with one at the top and the other at the bottom. Does anyone know how I can do this?

enter image description here

ClearAll[x, y];
x[t_] = Sin[50 t]/t + Cos[t];
y[t_] = Sin[30 t]/t^2 + Cos[t^2];
sub1 = Plot[x[t], {t, 1, 2}, PlotStyle -> {Blue, Red}, 
   PlotRange -> All];
sub2 = Plot[y[t], {t, 1, 2}, PlotStyle -> {Blue, Red}, 
   PlotRange -> All];
Plot[{x[t], y[t]}, {t, 0, 2 Pi}, PlotStyle -> {Blue, Red}, 
 Epilog -> Inset[sub1, Scaled[{.3, .6}], Scaled[{0, 0}], 3], 
 PlotRange -> {-12, 12}, PlotRangeClipping -> False]
$\endgroup$
2
  • 1
    $\begingroup$ Just make the argument to Epilog a list: Epilog->{Inset[...],Inset[...]} $\endgroup$
    – lericr
    Apr 12, 2023 at 23:14
  • $\begingroup$ @lericr Didn't know you could do that. Why does this not work Epilog -> {Inset[sub1, Scaled[{.3, .6}], Scaled[{0, 0}], 3], Inset[sub2, Scaled[{.3, -0.6}], Scaled[{0, 0}], 3]}? $\endgroup$
    – hana
    Apr 12, 2023 at 23:20

1 Answer 1

5
$\begingroup$

You need to be careful when you use the Inset with the 3rd argument as the position is relative. A more "intuitive" method would be to scale the image using ImageSize and then using Inset with only two arguments, the second being Scaled.

ClearAll[x, y];
x[t_] = Sin[50 t]/t + Cos[t];
y[t_] = Sin[30 t]/t^2 + Cos[t^2];
sub1 = Plot[x[t], {t, 1, 2}, PlotStyle -> {Blue}, PlotRange -> All];
sub2 = Plot[y[t], {t, 1, 2}, PlotStyle -> {Red}, PlotRange -> All];
Plot[{x[t], y[t]}, {t, 0, 2 Pi}, PlotStyle -> {Blue, Red}, 
 Epilog -> {Blue, Inset[sub1, Scaled[{0.3, .6}], Scaled[{0, 0}], 3], 
   Inset[sub2, Scaled[{.3, 0.6}], Scaled[{0, 1.4}], 3]}, 
 PlotRange -> {-12, 12}, PlotRangeClipping -> False]

enter image description here

$\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.