Message Boards Message Boards

1
|
4428 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Issue when plotting rectangular region with RegionPlot?

I came across a glitch in RegionPlot when plotting a simple implicitely defined rectangular region: the corners of the rectangle are clipped. It appears only when setting PlotRange to Full while with an explicitely set identical PlotRange, the glitch vanishes. Furthermore, when defining the rectangle explicitely using ParametricRegion instead of ImplicitRegion, there is also no problem. For illustration see the code below. Any idea what may cause this? Ist it a bug or a feature? I suspect the observed behaviour might result from different meshing of the region internally, however, I wonder why the same region results in different plots depending on how PlotRange is set.

lx = 5;
ly = 10;

regi = ImplicitRegion[0 <= x <= lx && 0 <= y <= ly, {x, y}];

plotl = RegionPlot[regi,
   Frame -> True,
   AspectRatio -> Automatic,
   PlotRange -> Full];

plotm = RegionPlot[regi,
   Frame -> True,
   AspectRatio -> Automatic,
   PlotRange -> {{-lx/50, lx + lx/50}, {-ly/50, ly + ly/50}}];

rege = ParametricRegion[{x, y}, {{x, 0, lx}, {y, 0, ly}}];

plotr = RegionPlot[rege,
   Frame -> True,
   AspectRatio -> Automatic,
   PlotRange -> Full];

GraphicsRow[{plotl, plotm, plotr}, ImageSize -> Large]

Output of code above

POSTED BY: Karl Krieger
3 Replies

It's definitely the way the region mesh is generated using the region function. All the options of the resulting plots are similar with the exception of the PlotRange and PlotRangePadding.

plotl = RegionPlot[regi, Frame -> True, AspectRatio -> Automatic, 
   PlotRange -> Full, Mesh -> All];
plotm = RegionPlot[regi, Frame -> True, AspectRatio -> Automatic, 
   PlotRange -> {{-lx/50, lx + lx/50}, {-ly/50, ly + ly/50}}, 
   Mesh -> All];
plotr = RegionPlot[rege, Frame -> True, AspectRatio -> Automatic, 
   PlotRange -> Full, Mesh -> All];

Select[Permutations[{lx, ly, 0, 0}, {2}], 
   RegionMember[regi, #] &] & /@ {regi, rege}

ops = InputForm[#][[1, 2]] & /@ {plotl, plotm, plotr};
com = Intersection @@ ops
Complement[#, com] & /@ ops

{plotl, plotm, plotr}

enter image description here

It seems the way the region is generated makes the difference.

{DiscretizeRegion[regi], Region[regi], DiscretizeRegion[rege], 
     Region[rege]}

This looks like that in RegionPlot, ImplicitRegion uses Region to start it's Mesh and ParametricRegion uses DiscretizeRegion to start its Mesh.

Table[RegionPlot[regi, AspectRatio -> Automatic, Mesh -> All, 
  MaxRecursion -> i], {i, 0, 3}]
Table[RegionPlot[rege, AspectRatio -> Automatic, Mesh -> All, 
  MaxRecursion -> i], {i, 0, 3}]

enter image description here

I just don't get why increasing the PlotRange to go just outside the region function changes everything.

POSTED BY: Martijn Froeling

The missing corners on the left-hand plot are a not uncommon phenomenon when one is trying to use equalities for regions. I'm sure this has popped up before on Wolfram Community or mathematica.stackexchage.com but at the moment am not finding it.

In any case, the documentation does not show this combination RegionPlot[ImplicitRegion[,,,]...].
However, the following (even with omitting PlotRange -> Full, which is superfluous here) gives the correct graphic.

RegionPlot[0 <= x <= 5 && 0 <= y <= 10, {x, 0, 5}, {y, 0, 10}, 
 Frame -> True, AspectRatio -> Automatic, PlotRange -> Full]
POSTED BY: Murray Eisenberg

Murray, thank your for your reply. As I found a workaround already (defining PlotRange explicitely, the middle plot), I posted my question rather out of curiosity what is going on under the hood of RegionPlot. I had found indeed a StackExchange post on this issue (https://mathematica.stackexchange.com/questions/156467/extra-edges-added-in-regionplot). Some comments there recommended increasing PlotPoints and/or MaxRecursion levels in RegionPlot, which I had already tried before and apparently do not resolve this behaviour at all. A helpful suggestion was to add Option Mesh->All to RegionPlot to show the grid used to discretize the region for plotting. As I suspected, RegionPlot appears to create different meshes depending on how the region was defined and how its PlotRange option was set; see below. I did not find this mentioned in the documentation. Might be helpful to add an explanation there. enter image description here

POSTED BY: Karl Krieger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract