Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 17 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
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
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 Bailey Jan 17 '12 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:

  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
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
@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
@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

Your Answer


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.