Function: crop - restrict a plot to a box

Calling sequence:

crop(P,[a..b,c..d],x);
crop(P,[a..b,c..d,e..f],x);

Parameters:

P - a two- or three-dimensional plot structure

a, b, c, d, e, f - real constants (possibly infinite)

x - (optional) anything

Description:

Examples:

Two plots, and their combination using display .

> A:= plot(x,x=0..1,colour=red):
B:= plot(1-x,x=0..1,colour=blue):
plots[display]([A,B],scaling=constrained);

The view option works on each individually, but not with the combination: it uses the largest rectangle containing both of the view rectangles, which in this case contains more of the red line than we ask for.

> Av:= plot(x,x=0..1,colour=red,view=[0..0.5,0..0.5]):
Bv:=plot(1-x,x=0..1,colour=blue,view=[0.2..0.8,0.2..0.8]):
plots[display]([Av,Bv],scaling=constrained);

Combining plots together with the use of crop .

> Ac:= crop(A,[0..0.5,0..0.5]):
Bc:= crop(B,[0.2 .. 0.8, 0.2 .. 0.8]):
plots[display]([Ac,Bc],scaling=constrained);

An example with a line segment, points, text and a polygon.

> P:= plots[display]({plot([[0,0],[10,10]],colour=red),
plots[pointplot]({seq([i,i+1],i=0..10)},colour=black,symbol=box), plots[polygonplot]([seq([i,(i-5)^2/2],i=0..10)],colour=cyan),
plots[textplot]({seq([i,i-1,convert(i,string)],i=0..10)},colour=blue)}): P;

> crop(P,[1 .. 5,3 .. 5]);

Using the optional third argument to ensure the whole box is in the plot:

> crop(P,[1..5,3..5],true);

A three-dimensional example:

> Q:= plots[display]({
plots[spacecurve]([[0,0,-3],[0,0,3]],colour=green),