clipping

A drawing can be clipped to an arbitrary path by first building a path with the path building functions such as moveto(); and lineto(); and then setting it up as the clip path with the clip(); function. The clip path must be set before the drawing to be clipped is made. In the following example a triangular path is made and then saved using gsave();. This path is then set up as the current clip path using the clip(); function. The path is then restored and stroked in order to show the clip path. The clip path is not ordinarily visible on the page. Finally the path is restored once more the y axis mirrored and the triangle filled. The result is the inverted triangle clipped against the original triangle.


 
#include <splot.h>
main()
   {
   translate(10,13);
   moveto(-4,-4);
   rlineto(10,0);
   alineto(10,120);
   closepath();
   gsave();
   clip();
   grestore();
   gsave();
   stroke();
   grestore();
   /* mirror about y axis */
   scale(1,-1);
   fill();
   }

Data drawn using drawdata(); or plotdata(); may be clipped to the most recently drawn axes box by setting set(AXESCLIP,ON ); before calling plotdata(); or drawdata();. This makes use of the clipping mechanism internally by temporarily adding the axes box to the clip path and then restoring the previous clip path after the data is drawn.