5
$\begingroup$

I have a complicated Manipulate that uses multiple locators, and need to document the output by saving the graphics to a file. The problem is that when I try to save the graphics, the locators disappear. Here is a simple case where the same problem occurs:

Manipulate[pts = PadRight[pts, n, RandomReal[{-1, 1}, {15, 2}]];
 disp = Graphics[Polygon[pts], PlotRange -> 1], {n, 5, 15, 1}, {{pts, {{0, 0}}}, Locator}]

enter image description here

If this looks familiar, it's because this is an example from the documentation for Manipulate, and I have only changed it by adding the disp =. In order to save the graphics to a file we can Export, but the problem is already present, since disp is

enter image description here

Notice that the locators have disappeared. So my question is this: is there a way to capture/rasterize/save the complete manipulate image (including the locators)?

$\endgroup$

1 Answer 1

9
$\begingroup$

You can make the Locators a part of the Graphics object instead of the Manipulate:

Manipulate[pts = PadRight[pts, n, RandomReal[{-1, 1}, {15, 2}]];
 disp = Graphics[{Polygon[pts], PlotRange -> 1, Locator /@ pts}], 
 {n, 5, 15, 1}, {{pts, {{0, 0}}}, Locator, Appearance -> None}]

Now you'll get a disp that looks like

disp

$\endgroup$
1
  • $\begingroup$ very clever -- I hadn't realized that Locators are just another graphics object. $\endgroup$
    – bill s
    Commented Mar 11, 2015 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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