How to shade different contours with different colors?

I want these two contours to be plotted in a single figure and filled the inner regions of each contour with different colors. The problem that I am facing is the larger contour shading overshadows the smaller one. I want the inner region to be red (for x1) and the rest of the inner region for the larger contour (for x2) to be blue. How do I achieve that?

x1 = ContourPlot[{a^2 + b^2 + a*b}, {a, -7, 7}, {b, -7, 7}, Contours -> {4},
ContourShading -> {Red, None}, MaxRecursion -> 5,
Epilog -> {Black, PointSize[0.015], Point[{0, 0}]},
ContourStyle -> {Red}, Frame -> True, FrameLabel -> {"a", "b"}];

x2 = ContourPlot[{a^2 + b^2}, {a, -7, 7}, {b, -7, 7}, Contours -> {9},
ContourShading -> {Blue, None}, MaxRecursion -> 5,
Epilog -> {Black, PointSize[0.015], Point[{0, 0}]},
ContourStyle -> {Blue}, Frame -> True, FrameLabel -> {"a", "b"}]

x4 = Show[{x1, x2}]

• Why aren't you using RegionPlot[]? RegionPlot[{a^2 + b^2 <= 9, a^2 + b^2 + a b <= 4}, {a, -7, 7}, {b, -7, 7}, BoundaryStyle -> Blue, Epilog -> {Black, PointSize[0.015], Point[{0, 0}]}, PlotStyle -> {Blue, Red}] Commented Jul 7, 2022 at 22:02
• Reverse the order in the Show: x4 = Show[{x2, x1}] Commented Jul 7, 2022 at 22:30
• @J.M. It is working. Thank you so much for your suggestion. Commented Jul 7, 2022 at 22:45
• @BobHanlon, It is working. Thank you so much. Commented Jul 7, 2022 at 22:46
• @J.M., One more question. According to your suggestion, both regions are enclosed by blue boundaries. Could you please tell me how to put two different color boundaries in the two different regions? Say, for the inner one black and for the outer one green. Commented Jul 7, 2022 at 22:55

Edit

{pts1, pts2} =
Cases[ContourPlot[{a^2 + b^2 + a*b == 4, a^2 + b^2 == 9}, {a, -7,
7}, {b, -7, 7}] // Normal, Line[pts_] :> pts, Infinity];
Graphics[{{Red, Polygon[pts1]}, {Blue, Polygon[pts2 -> pts1]}, {Green,
AbsoluteThickness[2], Line@pts1}, {AbsoluteThickness[2],
Line@pts2}, {AbsolutePointSize[5], Point[{0, 0}]}}, Frame -> True]


Original

Another way is use BoundaryDiscretizeGraphics to draw the gap between the two contours to blue.

x1 = ContourPlot[{a^2 + b^2 + a*b}, {a, -7, 7}, {b, -7, 7},
Contours -> {4}, ContourShading -> {Red, None}, MaxRecursion -> 5,
Epilog -> {Black, PointSize[0.015], Point[{0, 0}]},
ContourStyle -> Directive[Thick, Green], Frame -> True,
FrameLabel -> {"a", "b"}];
plot1 = ContourPlot[{a^2 + b^2 + a*b == 4}, {a, -7, 7}, {b, -7, 7},
ContourStyle -> Green];
plot2 = ContourPlot[a^2 + b^2 == 9, {a, -7, 7}, {b, -7, 7},
ContourStyle -> Black];
plot12 =
Graphics[{Blue,
BoundaryDiscretizeGraphics[
ContourPlot[{a^2 + b^2 + a*b == 4, a^2 + b^2 == 9}, {a, -7,
7}, {b, -7, 7}]]}]


Show[x1, plot12, plot1, plot2, PlotRange -> 4]


• It worked. Thank you so much. Commented Jul 8, 2022 at 8:09