# RegionPlot is producing odd gaps, even for simple functions. Is there an option to prevent this?

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:

Just increase the number of PlotPoints

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


• 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}. Commented Jan 17, 2012 at 22:58
• 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. Commented Jan 17, 2012 at 23:24

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


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]


• What are the tradeoffs between MaxRecursion and PlotPoints ? Commented Jan 17, 2012 at 22:44
• 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],RegionPlot[x^2<y&&y<x^4,{x,-3,3},{y,0,3},PlotPoints->100]] Commented Jan 17, 2012 at 22:53
• @ras See the edit. Commented Jan 17, 2012 at 23:00
• @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.) Commented Jan 18, 2012 at 5:01
• @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) Commented Jan 18, 2012 at 15:37