2
$\begingroup$

I'm having trouble creating a smooth animation which zooms in on a plot while the axes stay fixed. The application I have in mind is quite complicated, but the issue already arises in the following simplified version:

Table[Plot[x + 1/6, {x, 1/3 - epsilon, 1/3 + epsilon}, PlotRange -> {1/2 - epsilon, 1/2 + epsilon}, AxesOrigin -> {1/3, 1/2}, Ticks -> False], {epsilon, 3/4, 1/10, -.01}]

The resulting animation stays fixed as expected for the initial frames, then the axes drift right, then they pop back to the center and stay fixed for the rest of the animation:

Drifting axes

I'm at a loss for what to try, so any help is greatly appreciated!

EDIT: It appears this might be some kind of bug with Mathematica 10.0, it doesn't appear to be reproduceable in some older and newer versions.

$\endgroup$
3
  • 2
    $\begingroup$ Add options ImagePadding -> None, PlotRangePadding -> None to Plot $\endgroup$
    – Edmund
    Sep 27, 2017 at 22:22
  • $\begingroup$ @Edmund I think you should write this as an answer, rather than a comment. +1 $\endgroup$ Sep 28, 2017 at 6:53
  • $\begingroup$ With Edmunds hint you can try: Manipulate[Plot[x + 1/6, {x, 1/3 - epsilon, 1/3 + epsilon}, PlotRange -> {1/2 - epsilon, 1/2 + epsilon}, AxesOrigin -> {1/3, 1/2}, PlotRangePadding -> None, PlotRangePadding -> None], {epsilon, 3/4, 1/10, -.01}] $\endgroup$
    – mrz
    Sep 28, 2017 at 11:05

1 Answer 1

6
$\begingroup$

You may use the ImagePadding and PlotRangePadding options of Plot to control the extra automatically calculated spacings that are applied.

plots =
  Table[
   Plot[x + 1/6, {x, 1/3 - epsilon, 1/3 + epsilon},
    PlotRange -> {1/2 - epsilon, 1/2 + epsilon},
    AxesOrigin -> {1/3, 1/2},
    ImagePadding -> None,
    PlotRangePadding -> None
    ],
   {epsilon, 3/4, 1/10, -.01}];
ListAnimate[plots]

enter image description here

Hope this helps.

$\endgroup$
3
  • $\begingroup$ Thanks for the answer. For some reason when I tried my original code at home (On Mathematica 9.0) it worked just fine. I'll have to try your solution at work (Mathematica 11.something) to see if it fixes the issue. I had played around with some of the padding options but they didn't seem to help. $\endgroup$ Sep 28, 2017 at 14:04
  • $\begingroup$ @JackHuizenga This answer is on version 11.2, if that helps. $\endgroup$
    – Edmund
    Sep 28, 2017 at 15:15
  • $\begingroup$ Turns out my version at work is 10.0, and the above code produces the same output (+tick marks) as the original example I provided. Guess that's a reason to update to the latest version. Thanks! $\endgroup$ Sep 29, 2017 at 15:03

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.