Mathematica Asked on December 31, 2020
A gap appears at the locations of Exclusions at t=1,t=1+t0 when the top slider for t0 is set to Play. How can these gaps be avoided or filled in?
Manipulate[
y[t_, t0_] := 1/(1 - (t - t0));
y0[x_] := y[x, 0];
yT[x_] := y[x, t0];
Plot[{y0[t], yT[t]}, {t, -3, 7},
Exclusions -> {t == 1, t == 1 + t0},
PlotStyle -> {{Thick, Black}},
PlotRange -> {0, 3},
Frame -> True,
Axes -> False,
ImageSize -> 1.2 {500, 330},
BaseStyle -> {FontSize -> 16},
FrameLabel -> {t, x},
RotateLabel -> False,
PlotRangePadding -> {{2, 0}, {.1, .1}},
Epilog -> {PointSize[0.015], Red, Dashed,
Line[{{-4, y0[s]}, {s, y0[s]}}],
Point[{{-4, y0[s]}, {s, y0[s]}, {s + t0, yT[s + t0]}}],
Black, Dashing[{}], Line[{{-4, 0}, {-4, 3}}],
Red, Point[{-4, y1[s]}],
Black, Arrowheads[.03], Arrow[{{-4, 3}, {-4, 3.1}}],
Red, Dashing[{}], Line[{{s, y0[s]}, {s + t0, yT[s + t0]}}]}],
{{t0, 2}, -2, 5, 0.01},
{{s, 0}, -2, 0.67, 0.01}
]
I followed Mark McClure's suggestion concerning making two plots and combining them with Show
, and it indeed fixes your gap problem.
Manipulate[
Show[
Plot[y0[t], {t, -3, 6.5},
PlotRange -> {0, 3},
PlotStyle -> {{Thick, Black}},
Exclusions -> {t == 1}],
Plot[yT[t], {t, -3, 6.5},
PlotRange -> {0, 3},
PlotStyle -> {{Thick, Black}},
Exclusions -> {t == 1 + t0}],
Frame -> True, Axes -> False,
ImageSize -> 1.2 {500, 330},
BaseStyle -> {FontSize -> 16},
FrameLabel -> {"t", "x"},
RotateLabel -> False,
PlotRangePadding -> {{2, 0}, {.1, .1}},
Epilog ->
{
{Arrowheads[.03], Arrow[{{-4, 0}, {-4, 3}}]},
{Red, PointSize[0.015],
Point[{{-4, y0[s]}, {s, y0[s]}, {s + t0, yT[s + t0]}, {-4, y1[s]}}]},
{Red, Line[{{s, y0[s]}, {s + t0, yT[s + t0]}}],
Dashed, Line[{{-4, y0[s]}, {s, y0[s]}}]}
}],
{{t0, 2.}, -2., 5., 0.01, ImageSize -> Large},
{{s, 0.}, -2., 0.67, 0.01, ImageSize -> Large},
Initialization :>
(
y[t_, t0_] := 1/(1 - (t - t0));
y0[x_] := y[x, 0];
y1[x_] := y[x, 1];
yT[x_] := y[x, t0]
)]
While I was at it, I rewrote your epilog to make it more logical and concise, and I introduced an initialization option so that your local functions are only defined once (in your code they are redefined every time the content pane is refreshed). I also made a guess about y1
.
Correct answer by m_goldberg on December 31, 2020
Combinining consecutive Line
s into a single Line
and moving the function definitions to Initialization
(as suggested by @m_goldberg)
Manipulate[MapAt[# /. {x__, lines : Line[_] ..} :> {x,Line[Join @@ ({lines}[[All, 1]])]} &,
Plot[{y0[t], yT[t]}, {t, -3, 7},
Exclusions ->
{t == 1, t == 0.5, t == 0.5 + t0, t == 1 + t0}, (* with few more exclusions *)
PlotStyle -> {{Thick, Black}}, PlotRange -> {0, 3}, Frame -> True,
Axes -> False, ImageSize -> 1.2 {500, 330},
BaseStyle -> {FontSize -> 16}, FrameLabel -> {t, x},
RotateLabel -> False, PlotRangePadding -> {{2, 0}, {.1, .1}},
Epilog -> {PointSize[0.015], Red, Dashed,
Line[{{-4, y0[s]}, {s, y0[s]}}],
Point[{{-4, y0[s]}, {s, y0[s]}, {s + t0, yT[s + t0]}}], Black,
Dashing[{}], Line[{{-4, 0}, {-4, 3}}], Red, Point[{-4, yT[s]}],
Black, Arrowheads[.03], Arrow[{{-4, 3}, {-4, 3.1}}], Red,
Dashing[{}], Line[{{s, y0[s]}, {s + t0, yT[s + t0]}}]}], {1}] ,
{{t0, 2}, -2, 5, 0.01}, {{s, 0}, -2, 0.67, 0.01},
Initialization :> (y[t_, t0_] := 1/(1 - (t - t0));
y0[x_] := y[x, 0];
yT[x_] := y[x, t0])]
Before (with Plot[...]
instead of MapAt[..., Plot[...], ...]
):
After:
Answered by kglr on December 31, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP