-1
$\begingroup$

I want to zoom/exaggerate a portion of the following plot for t between 1 and 2, such that the zoomed portion is also within the main plot.

x[t_] = Sin[50 t]/t + Cos[t];
y[t_] = Sin[30 t]/t^2 + Cos[t^2];
P1 = Plot[x[t], {t, 0, 2 \[Pi]}, PlotStyle -> Blue];
P2 = Plot[y[t], {t, 0, 2 \[Pi]}, PlotStyle -> Red];
Show[P2, P1]

Please help.

$\endgroup$
5

3 Answers 3

4
$\begingroup$
x[t_] = Sin[50 t]/t + Cos[t];
y[t_] = Sin[30 t]/t^2 + Cos[t^2];
sub = Plot[{x[t], y[t]}, {t, 1, 2}, PlotStyle -> {Blue, Red}, 
  PlotRange -> All]
Plot[{x[t], y[t]}, {t, 0, 2 Pi}, PlotStyle -> {Blue, Red}, 
 Epilog -> Inset[sub, Scaled[{.3, .55}], Scaled[{0, 0}], 3], 
 PlotRange -> {-12, 12}, PlotRangeClipping -> False]

enter image description here

$\endgroup$
2
$\begingroup$
Show[P2, P1, 
 Epilog -> {Opacity[0.5], Yellow, Rectangle[{1, -2}, {2, 2}]}]
$\endgroup$
1
$\begingroup$

The highlighted region is under the plots of x[t] and y[t], so the plots are not covered by the plots like Epilog did.

In:

Remove[x, y, t, highlight]
x[t_] = Sin[50 t]/t + Cos[t];
y[t_] = Sin[30 t]/t^2 + Cos[t^2];
P1 = Plot[x[t], {t, 0, 2 \[Pi]}, PlotStyle -> Blue];
P2 = Plot[y[t], {t, 0, 2 \[Pi]}, PlotStyle -> Red];

HighlightRegion[f1_, f2_, a_, b_] := 
 Module[{t, xyMin, xyMax, highlight, fs},
  fs = {f1, f2};
  xyMin = 
   fs // Map[NMinValue[{#[t], a <= t <= b}, t] &] // {a, Min[#]} &; 
  xyMax = fs // 
     Map[NMaxValue[{#[t], a <= t <= b}, t] &] // {b, Max[#]} &;
  highlight = Graphics[{Yellow, Rectangle[xyMin, xyMax]}, Axes -> True]
  ]
highlight = HighlightRegion[x, y, 1, 2];
Show[highlight, P2, P1]

Out: enter image description here

$\endgroup$

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