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.

I am running Mathematica 7. In a Graphics environment I am setting Frame -> True (and using FrameLabel -> {"x", "y"} and PlotLabel -> "My Title", etc) so that I can see length scales in Graphics environments.

Suppose that I create a Disk of radius 0.9, centered at the origin. I have set PlotRange -> {{-1, 1}, {-1, 1}}. The result looks nice:

Graphics[{
  Cyan, Disk[{0, 0}, 0.9]
  },
 PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True, 
 FrameLabel -> {"x", "y"}, PlotLabel -> "My Disk"]

Disk 1

Now, however, suppose that I want to create a Disk that is not entirely contained in Frame. For example, I might leave PlotRange -> {{-1, 1}, {-1, 1}} and increase the Disk radius from 0.9 to 1.2. However, in the resulting image, the Disk goes beyond the boundaries of the Frame:

Graphics[{
  Cyan, Disk[{0, 0}, 1.2]
  },
 PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True, 
 FrameLabel -> {"x", "y"}, PlotLabel -> "My Disk"]

Disk 2

Is there any way that I can direct Mathematica to chop off parts of the Graphics objects that exist outside of the Frame? Thanks for your time.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

If I have understood correctly then PlotRangeClipping -> True is what you need:

Graphics[{Cyan, Disk[{0, 0}, 1.2]}, PlotRange -> {{-1, 1}, {-1, 1}}, 
 Frame -> True, FrameLabel -> {"x", "y"}, PlotLabel -> "My Disk", 
 PlotRangeClipping -> True]

enter image description here

share|improve this answer
add comment

Though not strictly a way to clip graphics, a similar result for a disk can be obtained with RegionPlot which automatically frames and clips regions.

r = 1.2;
RegionPlot[x^2+y^2 <= r^2, {x,-r,r}, {y,-r,r},
PlotRange->{{-1,1},{-1,1}}, PlotLabel->"My Disk"]

Mathematica graphics

share|improve this answer
2  
The reason is still the same as in Mike's answer :) RegionPlot just has it set to True by default. See Options[RegionPlot, PlotRangeClipping] and Options[Graphics, PlotRangeClipping] –  rm -rf Jan 13 '13 at 15:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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