1
$\begingroup$

I want to achieve something like this

Manipulate[Plot[Sin[x], {x, 0, r}, PlotRange -> {{0, 10}, {-1, 1}}], {r, 0.1, 10}]

but my function in place of Sin is an expensive function, and since what I want is only change of plot range, there is no need to recalculate the values every time. So I try this

p = Plot[Sin[x], {x, 0, 10}];
Manipulate[Show[p, PlotRange -> {{0, r}, {-1, 1}}], {r, 0.1, 10}]

but the plot axes is changing as I change r. So is it possible to manipulate the plot range of a plot with a fixed axes, without reevaluate it every time?

$\endgroup$
1
$\begingroup$

Also,

f = FunctionInterpolation[Sin[x], {x, 0, 2 Pi}]; 
Manipulate[ Plot[f[x], {x, 0, r}, PlotRange -> {{0, 2 Pi}, {-1, 1}}], {r, 0.1, 2 Pi}]
$\endgroup$
  • $\begingroup$ Thanks, but my function returns a list, and it seems FunctionInterpolation doesn't work this way: f = FunctionInterpolation[{Sin[x],Cos[x]}, {x, 0, 2 Pi}]; . Do you know how to deal with this? $\endgroup$ – xslittlegrass May 1 '13 at 2:23
  • $\begingroup$ OK, I think this works:f = Function[{t},{(FunctionInterpolation[Sin[x], {x, 0, 2 Pi}])[t],(FunctionInterpolation[Cos[x], {x, 0, 2 Pi}])[t]} Thanks for the help. $\endgroup$ – xslittlegrass May 1 '13 at 2:34
2
$\begingroup$

How about pulling out the data in the plot and making it into a ListPlot. You can then vary how much of the list you plot but keep the plot range the same.

p = Plot[Sin[x], {x, 0, 10}];
pdata=p[[1, 1, 3, 2, 1]];
Manipulate[ListLinePlot[pdata[[1 ;; m]],PlotRange -> {{0, 10}, {-1, 1}}], {m, 1, Length[pdata],1}]
$\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.