I'm experiencing a small problem with the edges of a square, if the PlotRange has the same size as the square :

aSquare = Graphics[{
    EdgeForm[Directive[Thick, Black]], GrayLevel[0.5], Opacity[0.1],
    Polygon[{{0, -Pi/2}, {Pi, -Pi/2}, {Pi, Pi/2}, {0, Pi/2}}]

    PlotRange -> {{0, Pi}, {-Pi/2, Pi/2}},
    PlotRangeClipping -> True,
    Frame -> None,
    Axes -> True,
    AxesOrigin -> {Pi/2, 0},
    AxesStyle -> GrayLevel[0.75]

This code will show the square with two sides having their thickness cut-off in part. All four sides should have exactly the same thickness.

I can solve the issue if I use PlotRange -> {{0 - 0.01, Pi + 0.01}, {-Pi/2 - 0.01, Pi/2 + 0.01}} instead, but this feels like an "hack", and don't seems to be very natural.

What should be the best way of showing that square with its thick borders, while still using the same size for PlotRange ? Take note that I need to keep PlotRangeClipping -> True to cut off some curves that goes outside the square.

  • $\begingroup$ Use PlotRange -> All in Show? $\endgroup$
    – kglr
    Apr 24, 2016 at 18:22
  • $\begingroup$ I'm not sure this will work, once I add all the curves. Those curves need to be shown inside the square only (thus the PlotRangeClipping -> True option). $\endgroup$
    – Cham
    Apr 24, 2016 at 18:24
  • $\begingroup$ Perhaps add a very small amount of padding to the plot range (e.g. PlotRangePadding -> 0.01)? Depending on how your curves are defined, which you don't specify, you might be able to use a RegionFunction to have them plotted only within the square. $\endgroup$
    – MarcoB
    Apr 24, 2016 at 21:51

1 Answer 1


I think it may be more expedient to use Framed to generate the frame you want, rather than having an extra graphics object:

      Graphics[{Red, Thick, Circle[]}],
      Plot[Sin[x], {x, -2, 5}, PlotStyle -> Directive[Thick, Blue]]
    PlotRange -> {{0, Pi}, {-Pi/2, Pi/2}},
    (*PlotRangeClipping -> True,*)
    Frame -> None, Axes -> True,
    AxesOrigin -> {Pi/2, 0}, AxesStyle -> GrayLevel[0.75],
    ImagePadding -> None
  FrameMargins -> 0,
  FrameStyle -> Directive[Thick, Black], 
  Background -> Directive[GrayLevel[0.5], Opacity[0.1]]

graphics results

  • $\begingroup$ I don't know why, but I don't get a thick frame. Removing Thickdoesn't make any difference. (what the ...?) $\endgroup$
    – Cham
    Apr 25, 2016 at 14:19
  • $\begingroup$ @Cham Could you try replacing Thick with an appropriate AbsoluteThickness directive? I tried AbsoluteThickness[3] in the FrameStyle and it looks OK, but you might want to try something outrageous, e.g. 10 or so, to see if it is even doing anything. I'm on 10.4.0; you are on a somewhat older version of MMA if I remember correctly, is that right? $\endgroup$
    – MarcoB
    Apr 25, 2016 at 14:29
  • $\begingroup$ @Cham Also, does the Circle show up as a thick line? That's also using Thick, so I wonder why it would work somewhere but not everywhere! $\endgroup$
    – MarcoB
    Apr 25, 2016 at 14:30
  • $\begingroup$ The Thickness doesn't change anything. The curves are all okay though. Yep, I'm on a prehistoric and archaic MMA 7. I'm currently playing with the Frame options. It appears to do the job for the moment. $\endgroup$
    – Cham
    Apr 25, 2016 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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