# Is there a way to change PlotRange without redrawing?

I'm running some code that takes a very long time to generate a final image. So naturally when the PlotRange on the original image was too small, I'm frustrated that I have to redraw it every time I adjust the scale.

Is there a way to rescale the graphic, without running the code all over again?

• Nope. Plot calculates the points only for your initial range. Something like Show[ yourPlot, PlotRange -> { otherRange, Automatic}] works only for smaller ranges – Dr. belisarius Sep 5 '15 at 20:58
• @belisarius: We don't know whether the OP is using Plot or some other drawing function. But still, suppose you used Plot but the PlotRange was too small in the $y$-axis, might the Show trick still work, or does Plot throw those points away? (I'd try it myself but I don't have Mathematica on this machine.) – user484 Sep 5 '15 at 21:31

In addition to what belisarius already noted, this plot can highlight another fact:

points = {};
g1 = Plot[Sin[x], {x, -Pi, Pi},
PlotRange -> {{-1, 1}, {-0.5, 0.5}},
EvaluationMonitor :> (points = {x, points})];


Above, I just accumulate in the list points the x values for which Sin has been calculated. The evaluation range is from -Pi to Pi, but the plot range is smaller.

The range of values for which the function Sin is evaluated is shown below and spans the values from -Pi to Pi, and not from -1 to 1: Instead, the graph g1 contains only the values within the y PlotRange. Below, for each Line, only the first and last points are shown, to shorten the output:

lines = Cases[g1, _Line, Infinity];
shortlines = lines /. Line[{a_, __, b_}] :> Line[{a, b}];
shortlines /. x_Real :> Round[x, 0.01] // InputForm


{ Line[{{-3.14, 0.}, {-2.97, -0.5}}],

Line[{{-2.27, -0.5}, {-1.92, 0.5}}],

Line[{{-1.22, 0.5}, {-0.87, -0.5}}],

Line[{{-0.17, -0.5}, {0.17, 0.5}}],

Line[{{0.87, 0.5}, {1.22, -0.5}}],

Line[{{1.92, -0.5}, {2.27, 0.5}}],

Line[{{2.97, 0.5}, {3.14, 0.}}] }

During display, the image is further reduced to the specified x PlotRange.

Consequently, not only the data in the chart is clipped with respect to the original evaluation range (so that information is lost forever) but a lot of computational effort is done which is later discarded.

So, if the function to be evaluated is computationally intensive, it may be very important to make the evaluation range equal to the x PlotRange, so that the function is not evaluated in useless points later discarded.