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$
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

| improve this answer | |
$\endgroup$
  • $\begingroup$ Simpler way to fix this: Row[{"a value = ", a}, ImageSize -> 100] $\endgroup$ – chyanog Sep 22 '19 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}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ that works, thanks a bunch! $\endgroup$ – crossingsymmetry May 18 '16 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$ – Jack LaVigne May 18 '16 at 20:49
  • $\begingroup$ @JackLaVigne it will still jitter when changing to 10.0 from 9.9 $\endgroup$ – BlacKow May 18 '16 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$ – Jack LaVigne May 18 '16 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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