Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Suppose we have the following simple RegionPlot:

f[x_] := 1 - x^2
g[x_] := 1 - 0.5 x^2
RegionPlot[{y < f[x], f[x] < y < g[x], y > g[x]}, {x, 0, 2}, {y, 0, 2}]

enter image description here

Now I'm trying to change the curve defined by $y=g[x]$ into a thick black curve, while leaving all other boundaries in the plot unchanged. I've tried adding the region $y=g[x]$ and playing with the plotstyle, which didn't work, and I've tried BoundaryStyle, which changed all the boundaries in the plot. Now I'm kinda out of ideas... Any help would be appreciated!

share|improve this question
1  
You can find what you are looking for here Reduce an equation by putting a new variable or here How do I solve this equation?. These posts deal with ContourPlot but you can do the same with RegionPlot. –  Artes Aug 24 at 9:26

2 Answers 2

up vote 4 down vote accepted

With

 f[x_] := 1 - x^2
 g[x_] := 1 - 0.5 x^2

You can use Epilog to add the thick line:

 RegionPlot[{y < f[x], f[x] < y < g[x], y > g[x]}, {x, 0, 2}, {y, 0, 2},
            PlotPoints -> 50,
            Epilog -> (Plot[g[x], {x, 0, 2}, PlotStyle -> {Black, Thick}][[1]]),
            PlotStyle -> {Directive[Yellow, Opacity[0.4]],
                         Directive[Pink, Opacity[0.4]],
                         Directive[Green, Opacity[0.4]]}]

or a combination of MeshFunctions, MeshStyle and Mesh with a small value (somehow 0. does not work):

RegionPlot[{y < f[x], f[x] < y < g[x], y > g[x]}, {x, 0, 2}, {y, 0, 2}, 
           PlotPoints -> 50,
           Mesh -> {{0.00001}}, MeshFunctions -> {Abs[#2 - g[#1]] &}, 
           MeshStyle -> Thick, 
           PlotStyle -> {Directive[Yellow, Opacity[0.4]], 
                         Directive[Pink, Opacity[0.4]], 
                         Directive[Green, Opacity[0.4]]}]

or Show to show the region plot with a second plot containing the thick line:

Show[RegionPlot[{y < f[x], f[x] < y < g[x], y > g[x]}, {x, 0, 2}, {y, 0, 2}, 
                PlotPoints -> 50,
                PlotStyle -> {Directive[Yellow, Opacity[0.4]],
                              Directive[Pink, Opacity[0.4]],
                              Directive[Green, Opacity[0.4]]}], 
      Plot[g[x], {x, 0, 2}, PlotStyle -> {Black, Thick}]]

to get

enter image description here

share|improve this answer
    
Ah, I tried some stuff with Epilog but didn't know I could put a Plot function inside. This is perfect, thanks a lot! –  ScroogeMcDuck Aug 24 at 9:52
1  
@ScroogeMcDuck, my pleasure. Please note the pattern Plot[...][[1]] -- not Plot[...] -- on the rhs of Epilog. And, thank you for the accept. Btw, it is advised that you wait a while before accepting an answer to encourage alternative/better answers. –  kguler Aug 24 at 10:02
    
Alright, I'll keep it in mind. –  ScroogeMcDuck Aug 24 at 10:32
Show[
 RegionPlot[{y < f[x], f[x] < y < g[x], y > g[x]}, {x, 0, 2}, {y, 0, 2}],
 RegionPlot[y > g[x], {x, -0.1, 2.1}, {y, -0.1, 2.1},
  BoundaryStyle -> Directive[Thick, Black]],
 PlotRangePadding -> None]

enter image description here

share|improve this answer

Your Answer

 
discard

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.