5
$\begingroup$

I'm trying to fill the region to the left of a vertical line with a pattern (Diagonal is enough for my purposes) and a different pattern to the right.

I've tried

ListPlot[{{18, 0}, {18, 30}}, Filling -> {1->{Top},1-> {Axis}}, 
 FillingStyle -> HatchFilling[], Joined -> True]

I get the message that neither Topnor Axis are valid Filling specifications, so part of the problem may be the fact that it's a vertical line. However, I get the same message if I try a slanted line

ListPlot[{{0, 0}, {18, 30}}, Filling -> {1 -> {Top}, 1 -> {Axis}}, 
 FillingStyle -> HatchFilling[], Joined -> True]

I imagine this is due to the fact that I only have two points in the ListPlot so I've also tried a different approach

 Graphics[{LightYellow, HalfPlane[{18, 0}, {18, 30}, {0, 0}]}, 
  Axes -> True, PlotRange -> {{0, 30}, {0, 30}}],

using a color rather than HatchFilling[] (which is my primary goal) because this is not a graphic primitive. This results in a blank graph and I'm confused as to why it doesn't work.

Edit Upon further research, I've discovered that HatchFilling was introduced in version 12.1 while I'm using 12.0.0.0. I'm guessing that using patterns was possible prior to 12.1 (though probably required a bit more work). I'd appreciate any pointers to achieve my desired result without using HatchFilling.

$\endgroup$
7
$\begingroup$

To fill the region under a curve, you need a curve that spans the x-PlotRange. E.g.:

ListLinePlot[{{{0, 30}, {18, 30}}, {{18, 0}, {18, 30}}, {{18, 
    30}, {35, 30}}}, Filling -> {{1 -> Axis}, {3 -> Axis}}, 
 FillingStyle -> {1 -> HatchFilling[-0.5], 3 -> HatchFilling[.5]}, 
 Joined -> True]

enter image description here

$\endgroup$
2
  • $\begingroup$ I've tried your proposed solution. I get filling not with patterns but with colours. I'm using Mathematica 12.0.0.0. Is it possible that HatchFilling was introduced in a latter version? $\endgroup$
    – Patricio
    Dec 2 '21 at 20:40
  • $\begingroup$ I think it was introduced in 12.1. I'll have to look for another solution $\endgroup$
    – Patricio
    Dec 2 '21 at 20:43
4
$\begingroup$

Edit

data1 = {{0, 30}, {18, 30}};
data2 = {{18, 30}, {35, 30}};
newdata1 = Join[{{data1[[1, 1]], 0}}, data1, {{data1[[-1, 1]], 0}}];
newdata2 = Join[{{data2[[1, 1]], 0}}, data2, {{data2[[-1, 1]], 0}}];
fig[color_, angle_] := 
  Graphics[{color, 
    Table[InfiniteLine[{0, i}, AngleVector[angle]], {i, -2, 2, .05}]},
    PlotRange -> 1/2];
RegionPlot[{WindingPolygon[newdata1], WindingPolygon[newdata2]}, 
 PlotStyle -> {Texture[fig[Cyan, π/4]], 
   Texture[fig[Brown, -π/4]]}, BoundaryStyle -> None, 
 Epilog -> {Thickness[Large], Green, Line[{{18, 0}, {18, 30}}]}, 
 PlotRange -> All]

enter image description here

Here we use Texture and WindingPolygon.Maybe work in 12.0 version.

data = Table[{x, Sin[x]}, {x, 1, 8, 0.01}];
newdata = Join[{{data[[1, 1]], 0}}, data, {{data[[-1, 1]], 0}}];
angle = π/4;
fig = Graphics[
   Table[InfiniteLine[{0, i}, AngleVector[angle]], {i, -2, 2, .05}], 
   PlotRange -> 1/2];
RegionPlot[WindingPolygon[newdata], PlotStyle -> Texture[fig], 
 TextureCoordinateFunction -> ({2 #1, 2 #2} &)]

enter image description here

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.