7
$\begingroup$

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.

$\endgroup$
11
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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

$\endgroup$
  • 2
    $\begingroup$ 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] $\endgroup$ – rm -rf Jan 13 '13 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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