Shading a region where an inequality is satisfied

Bug introduced in 9.0 or earlier and persisting through 11.0.1 or later

I'm creating solution sets for a calculus course and need to shade the region in $\mathbb R^2$ such that $x^2 < y < x^4$. This is what I have so far:

Plot[{x^2,x^4}, {x, -2, 2},PlotRange->{-1,5},PlotStyle->{Automatic,Red},
Filling->{1->{{2},{LightBlue,White}}}]


Unfortunately this gives me the following picture. In particular, the region in the interval $(-1,0)$ is shaded. How can I avoid this?

• Possible duplicate of Filling Between Curves – user9660 Oct 7 '15 at 7:02
• This looks like a duplicate but it isn't. The issue here is that the OP is using the correct syntax, but the filling is nevertheless incorrect (possibly caused by the curves touching at 0 but not crossing). Looks like a bug to me. I guess a workaround may be to lower the x^2 function a tiny bit. – Sjoerd C. de Vries Oct 7 '15 at 7:03
• I can reproduce the behavior in V9.0.1 and V10.2 – Michael E2 Oct 7 '15 at 10:44
• Same bug in Version 8 – Sjoerd C. de Vries Oct 7 '15 at 14:00

As I stated in my comment below the post, the filling syntax used by the OP is correct. The behavior seen in the plot is a bug.

A workaround is to simply increase the number of plot points. The following works:

Plot[{x^2, x^4}, {x, -2, 2},
PlotRange -> {-1, 5}, PlotStyle -> {Automatic, Red},
Filling -> {1 -> {{2}, {LightBlue, White}}},
PlotPoints -> 100
]


Update

Actually, it is not a small plot point number that seems to be the cause. Depending on the PlotPoint setting two of the four areas are either incorrectly filled or incorrectly not filled. The following plot shows the filling of those areas as a function of the PlotPoint value (1 is filled, 0 is not filled):

• Aha, nice catch +1. – user9660 Oct 7 '15 at 10:02
• There will be an update. There's more to it. – Sjoerd C. de Vries Oct 7 '15 at 10:03
• You beat me to your update: i.stack.imgur.com/O6ojv.gif. There's an interesting "discontinuity" at 49 and 53 plot points. The x^2 curve jumps to the x^4 for a point or two at x == 1. – Michael E2 Oct 7 '15 at 10:27
• @Michael Yes, I noted that as well. Do you agree that we can tag this question with the "bugs" tag? Also, can I use your animation as an additional illustration? – Sjoerd C. de Vries Oct 7 '15 at 10:30
• Yes, I think it's a bug. – Michael E2 Oct 7 '15 at 10:32

Since Filling shades between two curves in the plot, add an extra curve that serves as the limit.

Plot[{Max[x^2, x^4], x^2, x^4}, {x, -2, 2}, Filling -> {1 -> {2}},
PlotRange -> {-1, 5}]


To remember

Plot[{Min[x^2, x^4], x^2, x^4}, {x, -2, 2}, Filling -> {1 -> {2}},
PlotRange -> {-1, 5}]


• Aha! A clever trick indeed. Thanks! – user217285 Oct 7 '15 at 7:04

I got this here

Plot[{Max[x^2, x^4], x^2, x^4}, {x, -2, 2}, PlotRange -> {-1, 5},
PlotStyle -> {Automatic, Red}, Filling -> {1 -> {2}}]

• just saw the answer by @Lou which I believe is from the same source. – Hubble07 Oct 7 '15 at 7:00