2
$\begingroup$

I have to plot this region:

$$A = \{(x, y)\in [0, 2]\times [0, 1]; x+y \leq 2\}$$

Here is what I did:

Plot[{2 - x, 1}, {x, 0, 2},
Epilog -> {Orange, Line[{{2, 0}, {2, 1}}], Thickness[0.04]}]

The result is efficient, but yucky. Efficient because with the proper equation aside one can see which region we are talking about. Yucky because I would like the lines to have the same colour, and the region (the quadrilateral) to be filled with some pastel colour (like a light green).

How can I do it?

output from plot

$\endgroup$
3
  • $\begingroup$ Why don't you use ImplicitRegion and RegionPlot? RegionPlot[ImplicitRegion[x + y <= 2 && 0 <= x <= 2 && 0 <= y <= 1, {x, y}]] $\endgroup$
    – Domen
    Commented Mar 20, 2023 at 20:46
  • $\begingroup$ @Domen Because it just shows the quadrilateral, and it's not what I want $\endgroup$
    – Heidegger
    Commented Mar 20, 2023 at 20:49
  • $\begingroup$ Something like this? Plot[{2 - x, 1}, {x, 0, 2}, Filling -> {1 -> {2}} , PlotStyle -> Black]? $\endgroup$
    – march
    Commented Mar 20, 2023 at 21:17

4 Answers 4

6
$\begingroup$
Plot[{2 - x, 1, Min[2 - x, 1]}, {x, 0, 2}, Filling -> {3 -> 0}, 
 Exclusions -> None, 
 Epilog -> {Orange, Line[{{2, 0}, {2, 1}}], Thickness[0.04]}]

enter image description here

$\endgroup$
6
$\begingroup$

Combine ImplicitRegion, Plot and Rectangle by using Show.

Show[
 RegionPlot[
  ImplicitRegion[x + y <= 2 && 0 <= x <= 2 && 0 <= y <= 1, {x, y}], 
  PlotStyle -> LightGreen, BoundaryStyle -> None, 
  AspectRatio -> Automatic, PlotRange -> {{0, 2}, {0, 2}}, 
  PlotRangePadding -> 0.05],
 Plot[2 - x, {x, 0, 2}, PlotStyle -> Thick],
 Graphics[{FaceForm[None], EdgeForm[{Thick, ColorData[97][2]}], 
   Rectangle[{0, 0}, {2, 1}]}]
 ]

enter image description here

$\endgroup$
6
$\begingroup$
Clear["Global`*"];

Plot[{Min[2 - x, 1],
  Tooltip[2 - x, y == 2 - x],
  Tooltip[1, y == 1]},
 {x, 0, 2},
 PlotStyle -> ColorData[97][1],
 Filling -> 1 -> Axis,
 Epilog -> {ColorData[97][1],
   AbsoluteThickness[1.5], Line[{{2, 0}, {2, 1}}]}]

enter image description here

$\endgroup$
4
$\begingroup$
rectangle = Rectangle[{0, 0}, {2, 1}];

Plot[2 - x, {x, 0, 2},
 Filling -> {1 -> {1, White}},
 Frame -> True,
 PlotStyle -> Thick,
 Prolog -> {LightGreen, rectangle},
 Epilog -> {EdgeForm[{Thick, Orange}], FaceForm[], rectangle}]

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.