3
$\begingroup$

Is there an easy way to make HatchFilling use two alternating colors? E.g.

Show[
 RegionPlot[x^2 + y^2 < 1, {x, -1.2, 1.2}, {y, -1.2, 1.2}, PlotStyle -> Blue],
 RegionPlot[x^2 + y^2 < 1, {x, -1.2, 1.2}, {y, -1.2, 1.2}, PlotStyle -> {Red, HatchFilling[0, 10, 20]}]
]

Mathematica graphics

but without calling RegionPlot twice, since my real region to be plotted is computationally expensive.

$\endgroup$

1 Answer 1

2
$\begingroup$

Looks like HatchFilling does not support different colors for the lines and spacings. We can hack it as follows to color the spacings:

ClearAll[wthack]
wthack[clr_ : Blue][{d___, h_HatchFilling}] := PatternFilling[
  ColorReplace[Graphics[{d, h, Rectangle[]}], White -> clr], ImageScaled[1]]

Examples:

Row[{ RegionPlot[x^2 + y^2 < 1, {x, -1.2, 1.2}, {y, -1.2, 1.2}, ImageSize -> Medium, 
   PlotStyle -> wthack[][{Red, HatchFilling[0, 10, 20]}]],
  Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, ImageSize -> Medium, 
   Filling -> {1 -> {Axis, Pink}, 
    2 -> {Axis, wthack[Opacity[.5, Yellow]][{Blue, HatchFilling[Pi/3, 10, 30]}]}}]}, 
  Spacer[10]]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ For RegionPlot you can use the options MeshFunctions + Mesh + MeshShading to get the desired styling . See, for example, this Q/A. $\endgroup$
    – kglr
    Jun 25, 2020 at 4:55

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.