3
$\begingroup$

I want to plot Plot[{Sin[x], 0.3}, {x, 0, 2 \[Pi]}] with the portion below 0.3 highlighted as by lines as shown

enter image description here

$\endgroup$
6
$\begingroup$

Update: For version older than v 12.1 HatchFilling is not available. You can construct filling using RegionPlot with the options Mesh + MeshStyle (as in this answer) and use it as Epilog in Plot:

Plot[{Sin[x], 0.3}, {x, 0, 2 π}, 
 Epilog -> First[RegionPlot[0 < y <= .3, {x, 0, 2 Pi}, {y, -1, 1}, Mesh -> 20, 
    MeshFunctions -> {#1 - 2 #2 &}, 
    MeshStyle -> Directive[Orange, CapForm["Butt"], AbsoluteThickness[2]], 
    PlotStyle -> None, BoundaryStyle -> None]]]

enter image description here

Original answer:

You can use the option Filling as follows:

Plot[{Sin[x], 0.3}, {x, 0, 2 π}, 
  Filling -> 
   {2 -> {0, Directive[Opacity[.5], Orange, HatchFilling["Diagonal", 1, 5]]}}] 

enter image description here

Alternatively, you can use Filling + FillingStyle:

Plot[{Sin[x], 0.3}, {x, 0, 2 π}, 
 Filling -> {2 -> 0}, 
 FillingStyle -> Directive[Pink, HatchFilling["Diagonal", 5, 10]]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, but HatchFilling does not seem to be available in Mathematica 11.3 $\endgroup$
    – Mike
    Jun 12 at 13:48
  • $\begingroup$ @Mike, please see the update. $\endgroup$
    – kglr
    Jun 12 at 14:16

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.