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$
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$
  • $\begingroup$ The coolest ideas are often simple (when you know them ;-) ) $\endgroup$ – mgamer Feb 4 '18 at 11:37
  • $\begingroup$ thank you @mgamer. $\endgroup$ – kglr Feb 4 '18 at 12:05
1
$\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, privacy policy and cookie policy

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