1
$\begingroup$

I want Mathematica to excute the first action inside the Button fully before executing the second action. In particular, look at the following plot which I want to Export to a pdf.

Manipulate[myFigure=Show[Plot[x^2+a,{x,-1,1},PlotRange->{-1,4}]],{{a,2,"a"},-1,3},Button["Export a=0",{a=0,Export["Figure1.pdf",myFigure];}],Button["Export a=1",{a=1,Export["Figure2.pdf",myFigure];}]]

If I click Export, Mathematica seems to Export the plot before Updating the Manipulate to the new value for 'a'. However, I obviously want it to change to the new 'a' first, showing the new plot, and then Export this plot to a pdf.

Any thoughts on how to make Manipulate Dynamically Update itself before the Export? Or other solutions?

$\endgroup$
1
$\begingroup$

This works (at least for me):

Manipulate[
 myFigure = Dynamic@Plot[x^2 + a, {x, -1, 1}, PlotRange -> {-1, 4}],
 Column[{
   Slider[Dynamic@a, {-1, 3, 1}],
   Button["Export a=0", {a = 0; Export["Figure1.pdf", myFigure]}],
   Button["Export a=1", {a = 1; Export["Figure2.pdf", myFigure]}]
   }]
 ]
$\endgroup$
  • $\begingroup$ Thanks, works for me too. Kinda weird, as the whole point of having an expression inside a Manipulate is that the 'Dynamic@' is implied... But ok, it works. $\endgroup$ – LBogaardt May 30 '14 at 15:54
  • $\begingroup$ Actually, is there a way of Exporting the plot without having to name it? I think the order of the sequence is 1. change 'a', 2. Export, 3. give plot name. The 'Dynamic@' you proposed simply changes the order, with the naming as a 2nd step. By skipping the naming, and exporting the plot directly, the problem could also be solved. As in: Manipulate[Show[Plot[x^2+a,{x,-1,1},PlotRange->{-1,4}]],{{a,2,"a"},-1,3},Button["Export a=0",{a=0,Export["Figure1.pdf",this.Manipulate];}],Button["Export a=1",{a=1,Export["Figure2.pdf",this.Manipulate];}]] $\endgroup$ – LBogaardt May 30 '14 at 16:25
  • $\begingroup$ this.Manipulate doesn't exist in Mathemarica. $\endgroup$ – eldo May 30 '14 at 16:32
  • $\begingroup$ Yeah, obviously :P I was asking if a similar functionality exists. $\endgroup$ – LBogaardt May 30 '14 at 16:44
  • $\begingroup$ @LBogaardt - a similar functionality doesn't exist. $\endgroup$ – eldo May 30 '14 at 19:06

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.