3
$\begingroup$

I have the following straight line:

y[x_] = 4 x - 1;
Plot[y[x], {x, 0, 1}, PlotRange -> {{0, 1}, {0, 2}}]

I want to highlight the two regions separated by the straight line, such that they look nice and distinct.

$\endgroup$

2 Answers 2

8
$\begingroup$
y[x_] := 4 x - 1;
Plot[{y[x], y[x]}, {x, 0, 1}, PlotStyle -> Blue, 
 PlotRange -> {{0, 1}, {0, 2}}, 
 Filling -> {1 -> {Top, LightYellow}, 2 -> {Bottom, LightBlue}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ The coolest ideas are often simple (when you know them ;-) ) $\endgroup$
    – mgamer
    Feb 4, 2018 at 11:37
  • $\begingroup$ thank you @mgamer. $\endgroup$
    – kglr
    Feb 4, 2018 at 12:05
2
$\begingroup$

One can also use InfiniteLine[] and HalfPlane[] for this:

Graphics[{{LightYellow, HalfPlane[{0, -1}, {1, 4}, Cross[{1, 4}]]},
          {LightBlue, HalfPlane[{0, -1}, {1, 4}, -Cross[{1, 4}]]},
          {Blue, InfiniteLine[{0, -1}, {1, 4}]}},
         AspectRatio -> 1/GoldenRatio, Axes -> True, PlotRange -> {{0, 1}, {0, 2}}]

regions

$\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.