3
$\begingroup$

I want to plot a graph that looks like the following, where the blue curve is $y=x^2$ and the red lines are $y=8x-12$ and $y=-8x+20$. The filling is applied horizontally from the lines to the edge of the graph

enter image description here

I tried the following code, but the filling is as desired. Show[Plot[x^2, {x, -1, 4}], Plot[{-8 x + 20, 8 x - 12}, {x, -1, 4}, PlotStyle -> Red, Filling -> Top]]

enter image description here

Thank you!

$\endgroup$
3
$\begingroup$
Plot[{x^2, 8 x - 12, -8 x + 20}, {x, -1, 4}, 
 PlotStyle -> {Blue, Red, Red}, 
 Filling -> {2 -> {3}}, 
 AspectRatio -> 1, 
 PlotRange -> {-10, 10}]

enter image description here

The crucial part here is the Filling option. You can of course tweak this further to get what you want.

$\endgroup$
  • $\begingroup$ Note that MM is filling vertically between curve #2 & curve #3, rather than horizontally to the edges of the graph (which is how the OP had conceived of it.) In this case, these are equivalent, but there might be other cases where you might not be able to perform such a trick. $\endgroup$ – Michael Seifert Aug 17 '15 at 14:40
  • $\begingroup$ @MichaelSeifert Can you think of such a case? $\endgroup$ – yohbs Aug 17 '15 at 14:42

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.