3
$\begingroup$

I have the following code:

f[u_] = Graphics[{Circle[{0, 1}, 1],  Circle[{2 Sqrt[u], u}, u]}]
Manipulate[Show[f[u]], {{u, 0.5},1,10}]

Now, if we try the slider, we can actually see that when we make the second circle (the one for which its center and radius depend on $u$), the first "fixed" circle (the unit circle centered in $(0,1)$) will shrink in size in the picture.

What should I do in order to keep that circle "fixed" in size, i.e. no matter how big I make the second circle, the first circle remains fixed in size when using the slider? (so the image does not zoom in/out to see both circles)

$\endgroup$
  • $\begingroup$ Add an appropriate fixed PlotRange to your Show? $\endgroup$ – MarcoB Mar 27 at 21:24
1
$\begingroup$

Try something like this:

ClearAll[f]
f[u_] := Graphics[{Circle[{0, 1}, 1], Circle[{2 Sqrt[u], u}, u]}]
Manipulate[
 Show[
   f[u], 
   PlotRange -> PlotRange[f[10]], 
   PlotRangePadding -> Scaled[.05]
 ],
 {{u, 0.5}, 0.5, 10}
]

Here I use the PlotRange function to extract the plot range for the graphic with the largest possible circle, i.e. the one produced by f[10], then apply 5% padding to that range to make sure that everything fits comfortably.

$\endgroup$
  • $\begingroup$ This is exactly what I needed! Thank you! $\endgroup$ – QWE Mar 27 at 21:28
  • $\begingroup$ @QWE Glad to help! You are very welcome. $\endgroup$ – MarcoB Mar 27 at 21:28

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.