3
$\begingroup$

How can we obtain a plot that is shaded in a part. For example this plot:

enter image description here

$\endgroup$

2 Answers 2

5
$\begingroup$

One can use Prolog:

Plot[Cos[x],{x,-6,6},
     Prolog->{Opacity[0.2],Rectangle[{3,-1},{6,1}]}]

This gives

enter image description here

$\endgroup$
5
$\begingroup$
  • To fill the actual bounds of range of plot as OP, we use Scaled or ImageScaled.

  • For the range of OP, we set {{.7, 0}, {1., 1.}} as the range, see the illustration as below.

Graphics[{LightBlue, Rectangle[], LightRed, 
  Rectangle @@ {{.7, 0}, {1., 1.}}, Black, 
  Text[Style[{.7, 0}, 14], {.7, 0}, Background -> Yellow], 
  Text[Style[{1, 1}, 14], {1., 1.}, Background -> Yellow]}]

enter image description here

  • When we need the shadow does not cover the AxesLabel.
Plot[Cos[x], {x, -2 π, 2 π}, PlotStyle -> Red, 
 AxesLabel -> {Style["x", Red, 15], Style["y", Red, 15]}, 
 Epilog -> {GrayLevel[.3], Opacity[.5], 
   Rectangle @@ Scaled /@ {{0.7, 0}, {1., 1.}}}]

enter image description here

  • If we need to cover the AxesLabel, we should use ImageScaled and PlotRangeClipping -> False instead of Scaled.
Plot[Cos[x], {x, -2 π, 2 π}, PlotStyle -> Red, 
 AxesLabel -> {Style["x", Red, 15], Style["y", Red, 15]}, 
 Epilog -> {GrayLevel[.3], Opacity[.5], 
   Rectangle @@ ImageScaled /@ {{0.7, 0}, {1., 1.}}}, 
 PlotRangeClipping -> False]

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.