1
$\begingroup$

Basically, I want to create a movable, horizontal line, whose coordinates are (-4, h(t)) and (4, h(t)), that will move along the y-axis as t increases. Now, I already knew how to draw a movable dot:

MovieFrames = 
  Table[
    ListPlot[{{0, h[k / 10]}}, 
      PlotRange -> {{-1, 1}, {0, 75}}, PlotStyle -> Red], 
    {k, 0, 41}];

ListAnimate[MovieFrames, 
  AnimationRunning -> false, AnimationRepetitions -> 10, Animation -> Rate]

The above instructions will draw a movable dot that moves along the y-axis as t increases. I think the instruction for drawing a line is just like the extension to the above instruction, but I tried Graphics[Line..] and LisPlot, both of which did not work. Could someone give me a sample instruction for how to create a movable, horizontal line? Thank you in advance.

$\endgroup$
  • 1
    $\begingroup$ Please add your attempts to the question. This way, people are more likely to be able to help you. $\endgroup$ – Lukas Lang Feb 2 at 16:10
  • $\begingroup$ I will do that next time. Thanks for pointing this out. $\endgroup$ – Kai Qu Feb 4 at 12:44
1
$\begingroup$

You did not include the definition for h[t] so I will use

h[t_] = 10 t;

To make a line with ListPlot you need two points and the option Joined->True

MovieFrames =
  Table[
   ListPlot[
    {{-4, h[k/10]}, {4, h[k/10]}},
    Joined -> True,
    PlotRange -> {{-4, 4}, {0, 75}},
    PlotStyle -> Red],
   {k, 0, 41}];

or use ListLinePlot and the points are automatically joined

MovieFrames =
  Table[
   ListLinePlot[
    {{-4, h[k/10]}, {4, h[k/10]}},
    PlotRange -> {{-4, 4}, {0, 75}},
    PlotStyle -> Red],
   {k, 0, 41}];

or use ParametricPlot

MovieFrames =
  Table[
   ParametricPlot[{t, h[k/10]}, {t, -4, 4},
    PlotRange -> {{-4, 4}, {0, 75}},
    PlotStyle -> Red,
    AspectRatio -> 1/GoldenRatio],
   {k, 0, 41}];

or just Plot

MovieFrames =
  Table[
   Plot[h[k/10], {t, -4, 4},
    PlotRange -> {{-4, 4}, {0, 75}},
    PlotStyle -> Red,
    AspectRatio -> 1/GoldenRatio],
   {k, 0, 41}];

ListAnimate[MovieFrames, AnimationRunning -> False, 
 AnimationRepetitions -> 10, AnimationRate -> 4]

enter image description here

$\endgroup$
  • $\begingroup$ Got it. Thank you all so much! $\endgroup$ – Kai Qu Feb 4 at 12:44
0
$\begingroup$

You might be able to use something a simple as this:

With[{ymax = 4},
  movieFrames =
    Table[
      ListPlot[{{-1, k/10}, {1, k/10}},
        Joined -> True,
        PlotStyle -> Red,
        PlotRange -> {Automatic, {0, ymax}}],
      {k, 0, 10 ymax}]];

ListAnimate[movieFrames,
  AnimationRunning -> False, AnimationRepetitions -> 2]

animation

$\endgroup$

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.