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$

2 Answers 2

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$
2
  • $\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$ May 1, 2013 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$ May 1, 2013 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$
0

Your Answer

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

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