Area-colored phase diagram for various ranges of f(a,b), given the ranges of a and b

Is there a way to plot a simple diagram in Mathematica with colored areas, like a phase diagram, for the different ranges of values of a function such $$f(a,b)=(1-a)/(b+2)$$, for various combinations of $$a$$ & $$b$$?

I mean, for example, if $$0 and $$0, plot a diagram where the x-axis is $$a$$, and the y-axis is $$b$$, in which the area where $$1/4 is colored red, and $$0 is colored blue and the rest is white?

Try RegionPlot(I changed your example a little bit because of 0<f<1/2)

Show[{
RegionPlot[0 < (1 - a)/(2 + b) < 1/4, {a, 0, 1}, {b, 0, 2},PlotStyle -> Blue],
RegionPlot[1/4 < (1 - a)/(2 + b) < 1/2, {a, 0, 1}, {b, 0, 2},PlotStyle -> Red]
}]

• Great. Thank you! I have edited my question 'for the educational purpose', in-order to fit with your observation about f. Sep 18, 2019 at 15:02

You can use ContourPlot, specify the desired contours, and also use a non-default ColorFunction option. I also needed to use ColorFunctionScaling so that function values are left alone.

f[a_,b_] := (1-a)/(b+2)

ContourPlot[f[a, b], {a, 0, 1}, {b, 0, 2},
Contours->{0, 1/4, 1/2},
ColorFunction -> Function @ Piecewise[{{Red, 1/4<#<1/2}, {Blue, 0<#<1/4}}, White],
ColorFunctionScaling -> False
]

• Yes, thanks. Also works well. Sep 18, 2019 at 15:15
f[a_, b_] := (1 - a)/(b + 2)

You can use a single RegionPlot:

RegionPlot[{0< f[a,b] <= 1/4, 1/4 < f[a,b] <= 1/2}, {a, 0, 1}, {b, 0, 2},
PlotStyle ->{Blue, Red}, BoundaryStyle -> None]

Alternatively, RegionPlot with the options MeshFunctions+Mesh+ MeshShading:

RegionPlot[True, {a, 0, 1}, {b, 0, 2},
MeshFunctions -> {f[#, #2] &},
Mesh -> {{1/4, 1/2}},

ContourPlot[f[a, b], {a, 0, 1}, {b, 0, 2},
Contours -> { 1/4, 1/2},

same picture

Another alternative, using Filling

f[a_, b_] = (1 - a)/(2 + b);

boundary = b /. Solve[f[a, b] == 1/4, b][[1]]

(* -2 (-1 + 2 a) *)

Show[
Plot[boundary, {a, 0, 1},
PlotRange -> {0, 2},
Frame -> True,
Filling -> {1 -> #}] & /@
{{Bottom, Red}, {Top, Blue}},
AspectRatio -> 1,
FrameLabel -> (Style[#, Bold, 14] & /@ {a, b})]