2
$\begingroup$

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}}]
}];

Show[
    {aSquare},
    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.

$\endgroup$
  • $\begingroup$ Use PlotRange -> All in Show? $\endgroup$ – kglr Apr 24 '16 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 '16 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 '16 at 21:51
2
$\begingroup$

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

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

graphics results

| improve this answer | |
$\endgroup$
  • $\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 '16 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 '16 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 '16 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 '16 at 14:33

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.