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.

When I use RegionPlot to plot the region between two functions, I get strange gaps in the resulting figure. Is there a way to prevent this from happening?


For example,

RegionPlot[x^2 < y && y < x^4, {x, -3, 3}, {y, 0, 3}]

produces the following strange result:

enter image description here

share|improve this question
add comment

2 Answers

up vote 16 down vote accepted

Just increase the number of PlotPoints

RegionPlot[x^2 < y && y < x^4, {x, -3, 3}, {y, 0, 3}, 
  PlotPoints -> 100]

enter image description here

share|improve this answer
9  
As a note, some functions require a lot more than 100 points, I've needed upwards of 500 in some cases. Also, x and y can have different number of points via PlotPoints -> {100, 150}. –  rcollyer Jan 17 '12 at 22:58
3  
This same principle also applies to other Plot functions. Sometimes Mathematica gets unlucky with sampling the function and you get discontinuities or odd behavior. In almost every case, either increasing PlotPoints or MaxRecursion will help. –  Mike Bantegui Jan 17 '12 at 23:24
add comment

Or, the MaxRecursion:

RegionPlot[x^2 < y && y < x^4, {x, -3, 3}, {y, 0, 3},
  MaxRecursion -> 8]

The plot commands generally use a adaptive procedure that is applied recursively. MaxRecursion controls how many times this recursion can be applied. PlotPoints by contrast, simply indicates how many points should be used in the initial grid. It might be simplest to illustrate with the most basic Plot command:

Manipulate[
  Plot[Sin[x^2], {x, 0, 3},
    Mesh -> All, PlotRange -> 1.1,
    MaxRecursion -> mr, PlotPoints -> pp],
  {mr, 0, 8, 1}, {pp, 4, 100, 1}]

Mathematica graphics

This is a visualization of the sampling mesh for your example function:

RegionPlot[{x^2 < y && y < x^4, Not[x^2 < y && y < x^4]}, 
    {x, -3, 3}, {y, 0, 3}, Mesh -> All, MaxRecursion -> 4]

Mathematica graphics

share|improve this answer
    
What are the tradeoffs between MaxRecursion and PlotPoints ? –  raxacoricofallapatorius Jan 17 '12 at 22:44
2  
MaxRecursion is adaptive and should be the preferable solution (faster for a given required plot accuracy). Compare: ImageDifference[RegionPlot[x^2<y&&y<x^4,{x,-3,3},{y,0,3},MaxRecursion->8],Region‌​Plot[x^2<y&&y<x^4,{x,-3,3},{y,0,3},PlotPoints->100]] –  Andrew Moylan Jan 17 '12 at 22:53
    
@ras See the edit. –  Mark McClure Jan 17 '12 at 23:00
8  
@raxacoricofallapatorius PlotPoints is good for making sure features show up; MaxRecursion is better for "polishing" off the edges. (MaxRecursion generally can't improve something that isn't there to start with.) –  Brett Champion Jan 18 '12 at 5:01
3  
@AndrewMoylan Isn't it the case the to avoid holes or missing parts, one generally needs to increase PlotPoints, while MaxRecursion is only for increasing the accuracy of already found regions? While in this example it works well, I'm often a bit wary of MaxRecursion because of its exponential nature (increasing it by one may increase the plotting time significantly) –  Szabolcs Jan 18 '12 at 15:37
show 3 more comments

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.