# Animated plot required to leave behind trace

Animate[Plot[2 x a - a^2, {x, -2, 2}], {a, -2, 2}, AnimationRunning -> False]


During run I need the output to display two things

1. Leave a trace of the straight line tangent on a default increment of animation parameter a.
2. Prevent the axes from quivering (not steady) while axes are scaled for each plot.

By specifying fixed range/domain limits can I effectively fix the 2nd problems?

EDIT1:

a = 1; plt1 = Plot[2 x a - a^2, {x, -2, 2}];
a = .5; plt2 = Plot[2 x a - a^2, {x, -2, 2}];
a = -.5; plt3 = Plot[2 x a - a^2, {x, -2, 2}];
a = -1; plt4 = Plot[2 x a - a^2, {x, -2, 2}];
Show[{plt1, plt2, plt3, plt4}]


EDIT2:

BTW, it is solution of Clairaut's Differential equation

$$y = 2p-p^2,\, p= \frac{dy}{dx},$$

with singular solution

$$y=x^2$$

which can be seen here.

• Ad 2) just add PlotRange -> {-10, 5} (or any plot range that looks appealing to you) in the Plot. – corey979 Nov 11 '16 at 22:19
• Thanks, Some of fleeting lines 1) need also to be captured. – Narasimham Nov 11 '16 at 22:23
• Do you know how to make a static plot showing the set of tangents you want to see in the animation? If you do, then it's not hard to animate what you want. If not, you should work on the static plot first. When you done that come back with any questions about converted it an animation. – m_goldberg Nov 11 '16 at 22:26
• What do you mean by "leaving behind a trace"? Is this something you to do or is it something you want to suppress? You need to be clearer. – m_goldberg Nov 11 '16 at 22:33
• Yes. I choose a parameter value, plot to that value calling it plot1, likewise choose a second parameter labelled plot2 .... and Show them all. kind of nasty. – Narasimham Nov 11 '16 at 22:33

plots = Table[
Plot[2 x a - a^2, {x, -2, 2}, Filling -> Axis,
PlotRange -> {-5, 3}], {a, -1, 1, 0.1}];

frames = FoldList[Show, First @ plots, Rest @ plots];
(* or simply *)
frames = FoldList[Show, plots] (* thanks: Simon Woods *)

ListAnimate[frames, AnimationRate -> 2]


Exported with

Export["plot.gif", frames, "DisplayDurations" -> 1/2]

• In recent versions you can use frames = FoldList[Show, plots] – Simon Woods Nov 12 '16 at 8:30

This approach is slightly more complicated than corey979's but has the advantage that number of ghost lines is independent from the number of a you want to use (in other words, the animation below is "continuous", not step by step).

aMax = 4; (* max value of a *)
n = 30; (* number of ghost lines *)
f[x_, a_] = 2 x a - a^2;
lines = Table[Line[{{-aMax, f[-aMax, a]}, {aMax, f[aMax, a]}}], {a,
Subdivide[-aMax, aMax, n]}];
showLines[a_] := Block[{},
pos = Position[Subdivide[-aMax, aMax, n], _?(# < a &)];
If[Length@pos > 0, Graphics[{Lighter[Blue, .4], lines[[;; Last@Last@pos]]}],
Graphics[]]]
list = Table[ Show[Plot[2 x a - a^2, {x, -aMax, aMax}, PlotRange -> {{-3, 3}, {-10, 7}},
PlotStyle -> Darker[Blue, .5]], showLines[a],
Frame -> True], {a, -aMax, aMax, 0.1}];


• Exporting shown @corey979 – Narasimham Nov 11 '16 at 23:15
• @Narasimham I know this but I wanted to keep the Manipulate frame :) – anderstood Nov 11 '16 at 23:16
• See here, although - works for .avi, doesn't work for .gif. – corey979 Nov 11 '16 at 23:30
• @corey979 Yes I've seen this, but when converting the avi to gif rendered strange colors... Nevermind, I exported without the frame :) – anderstood Nov 11 '16 at 23:35

My bid for your consideration. First I would simplify the Plot to a single Line segment, then abstract this to a function:

(* s = start; i = increment *)

fn[s_, i_][f_] := Line @ Table[{{-2, -4 a - a^2}, {2, 4 a - a^2}}, {a, s, f, i}]


From there I can animate smoothly as follows:

Animate[
Graphics[{{LightGray, fn[-2, 0.2][a]}, fn[a, 1][a]}
, PlotRange -> {-5, 3}
, AspectRatio -> 1/GoldenRatio
, Axes -> True
]
, {a, -2, 2}
, AnimationRate -> 1
, RefreshRate -> 60
, DisplayAllSteps -> True
]


Animation:

• Small detail: for the animation, I changed the order in Graphics so that the main line is on top. – anderstood Nov 12 '16 at 20:47
• @anderstood Thanks for the .GIF, and the note on order. I'll correct that in the code. – Mr.Wizard Nov 13 '16 at 0:11
• I'm too lazy to write an answer, so: InfiniteLine[{0, -a^2}, {1, 2 a}] works well for depicting the lines, and it is easy to see how it was derived from the original equation of the line. – J. M.'s technical difficulties Dec 9 '16 at 22:16
• @J.M. Thanks for the suggestion. It's good to see you posting again, by the way. :-) – Mr.Wizard Dec 11 '16 at 13:47
• Yeah, it's great to be back; I was sick for most of my hiatus, so being able to post here again is nice. – J. M.'s technical difficulties Dec 11 '16 at 13:49