0
$\begingroup$

For example, I've got the following code:

Plot[{x >= 5, y >= 8, x + 2y <= 64, x + y <= 40}]

This would plot:

enter image description here

Now, this is fair enough. It shows me the graphical solution of my four inequalities, however, I also would like to have the lines of those inequalities to be plot as well alongside the graphical solution of my inequalities. How would I do that?

$\endgroup$
1
$\begingroup$

Amplifying on Bill's answer

Legended[
 Show[
  RegionPlot[
   x >= 5 && y >= 8 && x + 2 y <= 64 && x + y <= 40, {x, 0, 40}, {y, 
    0, 35},
   Frame -> True,
   FrameLabel -> (Style[#, 14, Bold] & /@ {x, y}),
   PlotPoints -> 100],
  ContourPlot[
   Evaluate[
    Tooltip /@ {x == 5, y == 8, x + 2 y == 64, x + y == 40}],
   {x, 0, 40}, {y, 0, 35}],
  PlotLabel -> Style[
    x >= 5 && y >= 8 && x + 2 y <= 64 && x + y <= 40,
    14, Bold]],
 Placed[
  LineLegend[
   ColorData[97] /@ Range[4],
   {x == 5, y == 8, x + 2 y == 64, x + y == 40}],
  {0.75, 0.75}]]

enter image description here

$\endgroup$
0
$\begingroup$

Try

Show[
  ...yourexistingplot...,
  ContourPlot[{x == 5, y == 8, x + 2y == 64, x + y == 40},{x,5,35},{y,5,30}]
]

which should overlay your two plots and show you your colored lines along the edges.

You can adjust the PlotRange option as needed to frame the plots.

$\endgroup$
0
$\begingroup$

Just a slightly compact way of Bob Hanlon's answer (which I voted for). Note ContourPlot frames and uses Tooltip. The aesthetics and control of Legended may be preferred.

cons = {x >= 5, y >= 8, x + 2 y <= 64, x + y <= 40};
eq = cons /. {(a_ >= b_) :> (a == b), a_ <= b_ :> a == b};
Show[RegionPlot[lab = Fold[And[#1, #2] &, cons], {x, 0, 35}, {y, 0, 35},
  PlotLabel -> Style[lab, Bold]], 
 ContourPlot[Evaluate[eq], {x, 0, 35}, {y, 0, 35}, PlotLegends -> "Expressions"]]

enter image description here

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