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$ Commented 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$ Commented 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$ Commented May 18, 2016 at 20:49
  • $\begingroup$ @JackLaVigne it will still jitter when changing to 10.0 from 9.9 $\endgroup$ Commented 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$ Commented May 18, 2016 at 22:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.