1
$\begingroup$

I am making animations for educational purposes that compare projectile trajectories in different environments. Each animation starts with a reference trajectory. Then, at least one projectile is superimposed and released.

In most cases, these projectiles travel a lot higher and a lot farther than the reference trajectory, but I don't want to give that away at the beginning. So, each animation starts with a plot range that nicely encompasses reference trajectory. Then, as the featured projectile moves, the plot range expands to keep it in view.

I want this expansion to be smooth. However, whenever a new tick label appears, the plot range jumps forward to accommodate said label. The expansion then freezes until the projectile reaches the end of the new plot range, at which point the expansion continues smoothly until a new tick label appears and the process repeats. The result is an animation that is not smooth and not to my liking.

Here is a simplified example I've been playing around with:

referenceFunction = {132.09935961236326` t, 
  3.2808398950131235` + 70.8667452497465` t - 16.076115485564305` t^2}

referenceBounds = t /. Solve[0 == Last@referenceFunction]
PrependTo[referenceBounds, t]

referenceTrajectory = 
 ParametricPlot[Evaluate@referenceFunction, Evaluate@referenceBounds, 
  PlotStyle -> {Gray, Dashed}]

exampleFunction[t_] = {132.09935961236326` t, 
  3.2808398950131235` + 70.8667452497465` t - 2.662724845231996` t^2}

{tStart, tStop} = t /. Solve[0 == Last@exampleFunction[t]]

exampleTrajectory[time_] := 
 ParametricPlot[exampleFunction[t], {t, tStart, time}]

showOptions = {ImageSize -> Large, GridLines -> Automatic, 
   Axes -> False, Frame -> {True, True, False, False}, 
   FrameLabel -> {"Horizontal Label", "Vertical Label"}, 
   LabelStyle -> {Black, Larger}, PlotRange -> {{0, All}, {0, All}}, 
   PlotRangePadding -> {{0, Automatic}, {0, Automatic}}};

animateThis[time_] := 
 Show[{referenceTrajectory, exampleTrajectory[time]}, showOptions]

Animate[animateThis[time], {time, 0, tStop}, DefaultDuration -> tStop,
  DisplayAllSteps -> True]

I am using Frame and FrameTicks instead of Axes and Ticks because I prefer the centered and rotated positions of FrameLabel. The same problem occurs with Axes and Ticks.

I have tried several potential fixes, including but not limited to writing custom PlotRange functions, trying different PlotRangePadding and FrameTicksStyle options, turning GridLines off, etc. So far, nothing aside from removing the frame tick labels altogether has worked, and I prefer having those labels! I just don't want them to affect PlotRange when they render.

So, I am deferring to the experts; any help is appreciated.

$\endgroup$
2
  • 2
    $\begingroup$ Adding ImagePadding -> 60 to your showOptions seems to work. $\endgroup$ – Ben Izd Apr 7 at 18:56
  • $\begingroup$ I hadn't considered using any Image options, but ImagePadding -> {{Automatic, 0}, {Automatic, 0}} gives me exactly what I'm looking for. Thanks! If you'd like some extra reputation, write this solution as an answer and I'll give it the accept. $\endgroup$ – Aaron Eiben Apr 7 at 21:26

Your Answer

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

Browse other questions tagged or ask your own question.