3
$\begingroup$

Following I have a simple animation with a variable displayed inside the plot. The significant digits of the variable changes as you run the animation which results in a smaller jitter on the text's initial position. It might be small but I find it very distracting when the animation is saved as a video.

Animate[Plot[Sin[a*t], {t, 0, 2}, PlotRange -> {0, 2}, Epilog -> Text[Style[Row@{"a value = ", a}, Bold, Blue, 15], {1, 1.5}]], {a, 0, 10, 0.1}]

Is there a way to get rid of the jitter in the text display. I believe by forcing the initial position of the text to be a fixed value we should be able to get rid of the jitter, but I don't know how to do it.

Thanks,

$\endgroup$

2 Answers 2

3
$\begingroup$
Animate[Plot[Sin[a*t], {t, 0, 2}, PlotRange -> {0, 2}, 
  Epilog -> Text[Style[Row[{"a value =", 
       Pane[a, Alignment -> Right, ImageSize -> {50, Automatic}], 
       "  some more text"}], Bold, Blue, 15], {0.8, 1.5}]], {a, 0, 11,  0.1}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Simpler way to fix this: Row[{"a value = ", a}, ImageSize -> 100] $\endgroup$
    – chyanog
    Sep 22, 2019 at 11:58
6
$\begingroup$

Maybe you could fix the left-hand end of the text position, something like this:

Animate[Plot[Sin[a*t], {t, 0, 2}, PlotRange -> {0, 2},Epilog->Text[Style[Row@{"a value = ", a}, Bold, Blue, 15], {0.8, 1.5}, {-1,
  0}]], {a, 0, 10, 0.1}]
$\endgroup$
4
  • $\begingroup$ that works, thanks a bunch! $\endgroup$ May 18, 2016 at 20:32
  • $\begingroup$ Another approach would be to use NumberForm[a, {2,1}] rather than a as the third component of the Row. $\endgroup$ May 18, 2016 at 20:49
  • $\begingroup$ @JackLaVigne it will still jitter when changing to 10.0 from 9.9 $\endgroup$
    – BlacKow
    May 18, 2016 at 21:31
  • $\begingroup$ @BlacKow You are right. I missed the 10. Using NumberPadding perfectly aligns numbers when I place them in a column (NumberForm[a, {3, 1}, NumberPadding -> {" ", "0"}]) but when I place it in the Animate the 10 jitters. I am sticking with demm's solution. $\endgroup$ May 18, 2016 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.