4
$\begingroup$
Plot[-x^3 + 2 x^2 + 8 x, {x, -5, 5}, Filling -> Axis]

produces this

enter image description here

What's the easiest way to change to something like this

enter image description here

That is, I only need the two "humps".

I have tried this:

Show[
    Plot[-x^3 + 2 x^2 + 8 x, {x, -5, 5}],
    Plot[-x^3 + 2 x^2 + 8 x, {x, -2, 4}, Filling -> Axis]
]

which gives what I want, but it looks too dumb ... and there must be an easier way

$\endgroup$
7
$\begingroup$

Try

Plot[{-x^3 + 2 x^2 + 8 x, ConditionalExpression[-x^3 + 2 x^2 + 8 x, -2 <= x <= 4]}, 
 {x, -5, 5}, 
Filling -> {2 -> Axis}, PlotStyle -> Red]

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.