3
$\begingroup$

I want to fill the region below the horizontal line at 50.9 with tilted lines. For recent versions of Mathematica, this can be done using HatchFilling[]. I am using v11 that does not support it.

Question

What can be done to fill the indicated region using tilted lines but without using HatchFilling[]?


Here is my code for the plot:

Subscript[θ,23][δ_, θ12_, θ13_, α_, β_] := -(180/(2 π)) ArcTan[(Cos[(2 (α + β + δ) ) Degree] Sin[2 θ12 Degree] Cos[θ13 Degree] )/(Cos[(2 (α + β) + δ) Degree] Cos[θ12 Degree]^2 Sin[2 θ13 Degree])];
Tab1 = Table[{δ,Subscript[θ, 23][δ, Random[Real, {31.61 , 36.27 }], 
         Random[Real, {8.22 , 8.99 }], Random[Real, {-6 , 6 }],Random[Real, {-45, -20 }]]}, {δ , 0 , 360, 1 Degree}];
     Tab2 =DeleteCases[Tab1, {_?(0 < # < 20 || 31 < # < 45 || 55 < # < 128 || 135 < # < 148 || 152 < # < 225 || 231 < # < 300 || 315 < # < 331 || 342 < # < 360 &), _}];
    P1 = ListPlot[ Tab2, Frame -> { True, True, True, True}, PlotRange -> {40, 55}, FrameLabel -> {δ, Subscript[θ, 23]}, FrameStyle -> Thick, PlotMarkers -> {Automatic, 5}, 
      BaseStyle -> {FontSize -> 14}, GridLines -> {{}, {50.9}}, GridLinesStyle -> Darker[Gray, .8],Method -> {"GridLinesInFront" -> True}]

    
$\endgroup$
1
  • $\begingroup$ Instead of using the deprecated Random[Real, ... construct, you can explore and use the RandomReal function. There are other related functions such as RandomInteger, RandomChoice, etc. $\endgroup$
    – Syed
    Sep 26, 2022 at 8:54

1 Answer 1

4
$\begingroup$

With HatchFilling[]

P0 = Plot[50.9, {x, 0, 400}, PlotStyle -> None, Filling -> Bottom, 
  FillingStyle -> Directive[Darker@Green, HatchFilling[]]
  ]

P1 = ListPlot[Tab2
  , Frame -> {True, True, True, True}
  , PlotRange -> {40, 55}
  , FrameLabel -> {δ, Subscript[θ, 23]}
  , FrameStyle -> Thick
  , PlotMarkers -> {Automatic, 5}
  , BaseStyle -> {FontSize -> 14}
  , GridLines -> {{}, {50.9}}
  , GridLinesStyle -> Darker[Gray, .8]
  , Method -> {"GridLinesInFront" -> True}
  , PlotRangePadding -> None
  ]

Show[P1, P0]

enter image description here


Without HatchFilling[]

Draw lines at an angle of choice before the plot using Prolog.

g = ListPlot[Tab2
  , Frame -> {True, True, True, True}
  , PlotRange -> {40, 55}
  , FrameLabel -> {\[Delta], Subscript[\[Theta], 23]}
  , FrameStyle -> Thick
  , PlotMarkers -> {Automatic, 5}
  , BaseStyle -> {FontSize -> 14}
  , GridLines -> {{}, {50.9}}
  , GridLinesStyle -> Darker[Gray, .8]
  , Method -> {"GridLinesInFront" -> True}
  , PlotRangePadding -> None
  , Prolog -> {
    Blue, Thin, Opacity[0.1]
    , Table[Line[{{a, 0}, {300 + a, 50.9}}], {a, -300, 400, 5}]
    }
  ]

enter image description here

$\endgroup$
5
  • $\begingroup$ Why HatchFilling is not working in my case? I think because mine is mathematica 11. Is it so? $\endgroup$ Sep 26, 2022 at 8:28
  • $\begingroup$ Is there any other way to do the same thing without using Hatchfilling? $\endgroup$ Sep 26, 2022 at 8:29
  • $\begingroup$ @SangeetaDey I have updated the answer. HatchFilling[] was introduced on {2020, 3, 18} whereas Mathematica 11 was introduced around August 2016. $\endgroup$
    – Syed
    Sep 26, 2022 at 8:41
  • $\begingroup$ Thank you so much. I am really grateful. $\endgroup$ Sep 26, 2022 at 8:56
  • $\begingroup$ You are most welcome. Thanks for the accept. $\endgroup$
    – Syed
    Sep 26, 2022 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.