Skip to main content
2 of 5
added 379 characters in body
kglr
  • 400.5k
  • 18
  • 488
  • 929

An alternative is to use Piecewise as follows

Plot[{Sin[x], Piecewise[{{Sin[x], -Pi <= x <= Pi}}, _]}, {x, -2 Pi, 2 Pi}, 
  Filling -> {2 -> {Axis, Yellow}}, PlotStyle -> {Green, Directive[Red, Thick]}] 

which gives

enter image description here

Or use Show to superimpose two variants (the second one with your choice of the variable bounds -- -Pi and 2Pi inn the example below) of the plot:

Show[Plot[Sin[x], {x, -3 Pi, 3 Pi}], 
     Plot[Sin[x], {x, - Pi, 2 Pi}, 
         Filling -> Axis, FillingStyle -> Yellow]]

enter image description here

kglr
  • 400.5k
  • 18
  • 488
  • 929