Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

related : – andre May 15 '13 at 19:41
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.