I want to make export of a plot inside Manipulate, but only once. However, this code runs infinitely and does export infinitely:

  pl = Plot[Sin[a x + b], {x, 0, 6}];
  Export["pl.pdf", pl];
 , {a, 1, 4}, {b, 0, 10}]

If I remove Export[] from Manipulate, problem disappears, but I need it inside Manipulate for other reason;)

Can we control number of evaluations of certain code inside Manipulate?

  • $\begingroup$ Can you please add version information? Which OS and which Mathematica version you are using? $\endgroup$ – Nasser Aug 14 '13 at 17:23

What about this (sans Module):

Manipulate[pl = Plot[Sin[a x + b], {x, 0, 6}], {a, 1, 4}, {b, 0, 10}, 
Button["Export", Export["pl.pdf", pl]]]

Mathematica graphics

  • $\begingroup$ "Clean clean" ♪ ♫ +1 $\endgroup$ – Mr.Wizard Aug 14 '13 at 16:04
  • $\begingroup$ @Mr.Wizard whuzzat (non sequitur)? $\endgroup$ – Yves Klett Aug 14 '13 at 16:07
  • 1
    $\begingroup$ Well, I looked at your answer and thought "that's clean." Then I thought of this. Yes, I know I'm weird. :o) $\endgroup$ – Mr.Wizard Aug 14 '13 at 16:09
  • $\begingroup$ LOL! Now I have to get that out of my head, thank you :-) $\endgroup$ – Yves Klett Aug 14 '13 at 16:14
  • $\begingroup$ But really the question was on why using Export was causing a Continuous updating since it should not be the case. I say this is bug or bad design somewhere in export. The 2 solutions given are simply work around. The problem itself has not gone away, because again, calling export[] should not have caused this. Even when adding SynchronousUpdating -> False which means do not time out, the Continuous updating is still there. $\endgroup$ – Nasser Aug 14 '13 at 16:58

It is a Dynamic problem. Export seems to be tagged dynamic somewhere. This is workaround. When I saw this, I remembered similar problem few days ago, and I used the same trick given there and it worked.

I set SynchronousUpdating -> False and ContinuousAction -> False else it will be very slow since you'll be trying to make a pdf file for each small tick change. Now a PDF file will be created when you release the mouse only from the slider.

SetDirectory[NotebookDirectory[]]; (*so we know where the PDF file is *)


  pl = Plot[Sin[a x + b], {x, 0, 6}];
  myExport["myPlot.pdf", pl];

 {a, 1, 4},
 {b, 0, 10},

 SynchronousUpdating -> False,
 ContinuousAction -> False,

 Initialization :> 
   myExport[type_String, p_] := myExport[type, p] = Export[type, p]

reference: Manipulate keeps updating due to a function


The problem as I saw it, is why Manipulate continue to update when using an Export when though Export is clearly not updating any of the control variables. On V 9.01, these are animations showing the problem. First animation is the original code posted above, and the second one, after adding SynchronousUpdating -> False.

The real question I assumed why: Why does this happen.

enter image description here


enter image description here


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.