Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by Michael E2, Sjoerd C. de Vries, Artes, m_goldberg, J. M. May 16 '13 at 4:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
related : mathematica.stackexchange.com/q/17700/5467 –  andre May 15 '13 at 19:41

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer

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