4
$\begingroup$

How can I fill the part above the line given in Epilog with light gray or something?

Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic, 
 Epilog -> {Directive[Red, Dashed, Thickness[0.008]], 
   Line[{{0, 1}, {1, 1}, {10, 10}}]}]

enter image description here

$\endgroup$

3 Answers 3

4
$\begingroup$
Clear["Global`*"]

Show[
 ListLinePlot[{{0, 1}, {1, 1}, {10, 10}},
  PlotStyle -> Directive[Red, Dashed, Thickness[0.008]],
  Filling -> Top,
  FillingStyle -> Lighter[Gray, 0.85]],
 Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic],
 PlotRange -> {{0, 3}, Automatic}]

enter image description here

EDIT: To obscure the lines by the Filling(adjust the Opacity to taste)

Show[
 Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic],
 ListLinePlot[{{0, 1}, {1, 1}, {10, 10}}, 
  PlotStyle -> Directive[Red, Dashed, Thickness[0.008]], Filling -> Top, 
  FillingStyle -> Opacity[0.75, LightGray]]]

enter image description here

$\endgroup$
6
  • $\begingroup$ Would it be OK to make those lines in the filling more blur? $\endgroup$
    – emnha
    Commented Mar 28, 2021 at 14:41
  • $\begingroup$ I noticed that you changed the order of these functions in Show. Does that matter? $\endgroup$
    – emnha
    Commented Mar 28, 2021 at 16:01
  • 1
    $\begingroup$ So reverse the order and compare the results. Does it make a difference? $\endgroup$
    – Bob Hanlon
    Commented Mar 28, 2021 at 16:13
  • $\begingroup$ I did but couldn't explain why $\endgroup$
    – emnha
    Commented Mar 28, 2021 at 16:16
  • 1
    $\begingroup$ So then you presumably already saw that it mattered. As to why, Show overlays the graphics: the first is the background and the second is the foreground. If the foreground is opaque you cannot see the corresponding background $\endgroup$
    – Bob Hanlon
    Commented Mar 28, 2021 at 16:26
2
$\begingroup$

Construct a polygon using the coordinates of the epilog line:

Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic, 
 Epilog -> {Directive[Red, Dashed, Thickness[0.008]], 
   Line[{{0, 1}, {1, 1}, {10, 10}}], 
   LightGray, Opacity[.5], 
   Polygon[{{0, 1}, {1, 1}, {10, 10}, 
      Scaled[{0, 1}, {10, 10}], 
      Scaled[{0, 1}, {0, 1}]}]}]

enter image description here

$\endgroup$
2
$\begingroup$

FilledCurve work for Line.

line = Line[{{0, 1}, {1, 1}, {10, 10}, {0, 10}}];
Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic, 
 Epilog -> {{Gray, Opacity[.5], FilledCurve[line]}, 
   Directive[Red, Dashed, Thickness[0.008]], 
   Line[{{0, 1}, {1, 1}, {10, 10}}]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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