Is there an option or method to prevent Graphics from being displayed outside the PlotRange region?

The problem is illustrated below: the gray lines are linear regressors and are being combined using Show with additional graphics.

The spill-over occurs both with and without PlotLabel set and only on the Top portion of the frame. But as I explain below it is more noticeable with PlotLabel set.

enter image description here

The same PlotRange -> {{0, 15}, {0, 175}} is set twice, once in the main scatterplot that renders the frame (it is built up with Graphics elements rather than a ListPlot), and also in the call to Show which combines the scatterplot, highlighted points and the regressors.

But I've also tried removing PlotRange independently in either, with no change in results.

Removing PlotLabel causes the out-of-bounds portion of the lines to be considerably shortened but still visibly outside the boxes.


You must add the option PlotRangeClipping -> True

Show[...,PlotRangeClipping -> True]    

Explanation of your results :

  • Show[gr1,gr2 ...] take the options of the first graphic in the list, gr1 here.

  • Concerning the scatterplot, Graphics[] has by default PlotRangeClipping -> False

  • Concerning the line, Plot[] has by default PlotRangeClipping -> True

So if gr1 is the Graphic with the scatterplot, the behavior you see is fully explained.


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