How to draw line animation using ListPlot?

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.

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

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] • Got it. Thank you all so much! – Kai Qu Feb 4 at 12:44

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] 