1
$\begingroup$

I want to slide the blue point with Manipulate[]. However, the following code does not function:

Manipulate[
     Plot[{0, 0}, {x, 500, 1000}, 
         Prolog -> Inset[Graphics[{PointSize[Large], Blue, Point[{nonTime, 0}]}]]], 
     {nonTime, 500, 1000}]

But, below code does work:

plt = Plot[{0, 0}, {x, 500, 1000}];
Manipulate[
    Show[{plt, Graphics[{PointSize[Large], Blue, Point[{nonTime, 0}]}]}], 
    {nonTime, 500, 1000}]

I wonder why the first piece code does not work.

$\endgroup$
2
$\begingroup$

Inset >> Details and Options

  • Inset[obj] is equivalent to Inset[obj,Center].

Since you don't use the second argument of Inset to specify the position, the Graphics object is placed at the center of the enclosing graphic.

So you can use {nonTime, 0} as the second argument in Inset to have the point dynamically move with the slider:

Manipulate[Plot[{0, 0}, {x, 500, 1000}, 
  Prolog -> Inset[Graphics[{PointSize[Large], Blue, Point[{0, 0}]}], 
   {nonTime, 0}]], 
 {nonTime, 500, 1000}]

enter image description here

If you don't have to use Inset a simpler alternative that gives the same result is to use

Prolog -> {PointSize[Large], Blue, Point[{nonTime, 0}]}
$\endgroup$
1
$\begingroup$

Without Prolog&Inset you can use Show:

Manipulate[
Show[{Plot[{0, 0}, {x, 500, 1000}], 
Graphics[{PointSize[Large], Blue, Point[{nonTime, 0}]}]
}], {nonTime, 500, 1000}]
$\endgroup$

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.