6

I am trying to shade the area bounded by the lines $y=2$, $y=-x+2$ and the parabola $y=x^2$. The plot is shown below. The area I'm talking about is the that bounded by the 4 black points. I am trying to shade it and I don't know how. Your assitance is appreciated.

Plot[{2 - x, x^2, 2}, {x, -3, 3}, PlotRange -> {-1, 5}, 
     PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}},  
     Epilog -> {Black, PointSize[0.025], Point[pts]}]

enter image description here

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
user47181
  • 85
  • 5
  • Show[ RegionPlot[y < 2 && y < 2 - x && y > x^2, {x, -2, 2}, {y, -1, 3}], Plot[{2 - x, x^2, 2}, {x, -3, 3}]] – Kuba Oct 27 '14 at 23:45
  • 2
    @Kuba Show[RegionPlot[Min[2, 2 - x] > y > x^2, {x, -2, 2}, {y, -1, 3}], Plot[{2 - x, x^2, 2}, {x, -3, 3}]] – Dr. belisarius Oct 28 '14 at 00:06

4 Answers4

7
Plot[{2 - x, x^2, 2}, {x, -3, 3}, PlotRange -> {-1, 5}, 
 PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}},
 Prolog -> 
  First@Show@
    BoundaryDiscretizeRegion[
     ImplicitRegion[y <= 2 - x && y <= 2 && y >= x^2, {x, y}]]
 ]

Mathematica graphics


Someday

BoundaryDiscretizeRegion[
 ImplicitRegion[y <= 2 - x && y <= 2 && y >= x^2, {x, y}]]["GraphicsComplex"]

will work reliably.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
6
pts = {{-Sqrt@2, 2}, {1, 1}, {0, 2}, {0, 0}};
opts = {PlotRange -> {-1, 5}, PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}}, 
        Epilog -> {Black, PointSize[0.025], Point[pts]}, 
        Filling -> {3 -> {{2}, {Transparent, Lighter@Lighter@Blue}}}};
Show[
 Plot[{2 - x, x^2, 2}, {x, -3, 0}, Evaluate@opts],
 Plot[{2, x^2, 2 - x}, {x, 0, 3}, Evaluate@opts], PlotRange -> All]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
5
Plot[{ConditionalExpression[x^2, x^2 <= Min[2, 2 - x]], Min[2, 2 - x],2 - x, 2, x^2}, {x, -3, 3}, 
 Filling -> {1 -> {2}}, FillingStyle -> Yellow, 
 PlotStyle -> {Directive[{Opacity[1], Yellow}], Opacity[0], 
   Directive[{Opacity[1], Red}], Green, Directive[{Dashed, Orange}]}, BaseStyle -> Thick]

enter image description here

Use MeshFunctions and Mesh to add the intersection points

Plot[{ConditionalExpression[x^2, x^2 <= Min[2, 2 - x]], Min[2, 2 - x],
   2 - x, 2, x^2}, {x, -3, 3},
 Filling -> {1 -> {2}}, FillingStyle -> Yellow, 
 Mesh -> {{0}, {0}}, MeshStyle -> PointSize[.03],
 MeshFunctions -> {# &, ConditionalExpression[Min[2, 2 - #] - #^2, #2 + # <= 2 && #2 <= 2] &}, 
 PlotStyle -> {Directive[{Opacity[1], Yellow}], Opacity[0], 
   Directive[{Opacity[1], Red}], Green, Directive[{Dashed, Orange}]}, 
 BaseStyle -> Thick]

enter image description here

ParametricPlot[{ConditionalExpression[{x, v x^2 + (1-v) Min[2, 2 - x]}, x^2 <= Min[2, 2 - x]], 
 {x, 2 - x}, {x, 2}, {x, x^2}}, {x, -3, 3}, {v, 0, 1}, 
 AspectRatio -> 1/GoldenRatio, PlotStyle -> ColorData[1, "ColorList"], 
 BaseStyle -> Thick, Frame -> False, Axes -> True, Mesh -> None]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
1
pts = {{-Sqrt@2, 2}, {1, 1}, {0, 2}, {0, 0}};
prolog = Plot[{x^2, Piecewise[{{2 - x, x > 0}, {2, x < 0}}]}, 
    {x, -Sqrt@2, 1}, Filling -> {1 -> {2}}][[1]];

I have applied prolog with Piecewise

Plot[{2 - x, x^2, 2}, {x, -3, 3}, PlotRange -> {-1, 5}, 
    PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}},
    Prolog -> prolog, 
    Epilog -> {Black, PointSize[0.025], Point[pts]}
]

Blockquote

Junho Lee
  • 5,155
  • 1
  • 15
  • 33