6
$\begingroup$

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!

$\endgroup$
6
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Ah, I tried some stuff with Epilog but didn't know I could put a Plot function inside. This is perfect, thanks a lot! $\endgroup$ – ScroogeMcDuck Aug 24 '14 at 9:52
  • 1
    $\begingroup$ @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. $\endgroup$ – kglr Aug 24 '14 at 10:02
  • $\begingroup$ Alright, I'll keep it in mind. $\endgroup$ – ScroogeMcDuck Aug 24 '14 at 10:32
4
$\begingroup$
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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.