Message Boards Message Boards

0
|
2673 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Color of Plots and Display "a" Value using Animate[ ]?

Posted 8 years ago
Animate[Plot[{x^2 - 1, x^2, -1/(2 a) (x - a) + a^2}, {x, -3, 3}, 
          PlotRange -> {{-3, 3}, {-2, 9}}, Axes -> {True}, 
          AspectRatio -> Automatic], {a, -1, 1}, RefreshRate -> 60, 
         AnimationDirection -> ForwardBackward, DefaultDuration -> 4]

So this works nicely, animating the normal line to y=x^2 from -1 to 1. However, I don't know how to color code each plot with Animate[] nor do I know how to show the value of "a" either on the plot or by the slider as it's changing. Can somebody please give an example of how I could make x^2 and the normal line the color black while x^2-1 is the color red? I'd also like the value of a to appear (and update/change as I'm playing the animation) next to the slider.

POSTED BY: John Travolski
2 Replies
Posted 8 years ago

Thanks, it works wonderfully!

POSTED BY: John Travolski

One way is to use PlotStyle and PlotLabel:

Animate[Plot[{x^2 - 1, x^2, -1/(2 a) (x - a) + a^2}, {x, -3, 3}, 
  PlotRange -> {{-3, 3}, {-2, 9}}, Axes -> {True}, 
  AspectRatio -> Automatic, PlotStyle -> {Black, Blue, Red}, 
  PlotLabel -> Row[{"a = ", a}]], {a, -1, 1}, RefreshRate -> 60, 
 AnimationDirection -> ForwardBackward, DefaultDuration -> 4]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract