4
$\begingroup$

For "RegionPlot", how to fill lines, points, or grids in different areas?

I have tried "Mesh", but it fills all region in same mesh.

I want to get the result just like this picture,

enter image description here

Thank you!

$\endgroup$
1
  • $\begingroup$ Please post your expression about the regions. $\endgroup$
    – cvgmt
    Apr 12 at 8:57

2 Answers 2

10
$\begingroup$
regions = {(x - 2)^2 < (y - 2)^3 + 1, (x - 2)^2 > (y - 2)^3 + 1 && 
    y > x - 3, y < Min[2, x - 3], x - 3 > y > 2 && x > 5};

You can specify PlotStyle using PatternFiling:

plotstyles = MapThread[PatternFilling[{#, #2}, ImageScaled[#3]] &, 
    {{"Diamond", "HalftoneGrid", "Grid", "Chevron"}, 
    ColorData[97] /@ Range[4], {1/40, 1/40, 1/40, 1/50}}];

RegionPlot[regions, {x, 0, 10}, {y, 0, 5}, 
  AspectRatio -> Automatic, ImageSize -> 700, 
  BoundaryStyle -> Thick, 
  PlotLegends -> SwatchLegend["Expressions", LegendMarkerSize -> 40], 
  PlotStyle -> plotstyles] /. 
 s_SwatchLegend :> (s /. ImageScaled[a_] :> ImageScaled[10 a]) 

enter image description here

Replace the last entry in plotstyles with HatchFilling:

plotstyles[[4]] = Directive[ColorData[97] @ 4, HatchFilling["Horizontal"]];

to get

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks! I think it's perfect, is this specific to 13? I'm still using 12, and maybe I need to update. $\endgroup$
    – hu_rrr
    Apr 12 at 9:48
  • $\begingroup$ @hu_rrr, HatchFilling and PatternFilling were introduced in version 12.1 $\endgroup$
    – kglr
    Apr 12 at 9:49
  • $\begingroup$ Thank you, you helped me a lot. $\endgroup$
    – hu_rrr
    Apr 12 at 9:57
  • $\begingroup$ @hu_rrr, my pleasure. Welcome to mma.se. $\endgroup$
    – kglr
    Apr 12 at 10:20
4
$\begingroup$

If it is good enough for you, you may fill with colors, using the option Filling:

Plot[{Sin[2 x], 1 + x^2, 2 + x}, {x, 0, 1}, Filling -> Automatic]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you! But I also want to get 3 regions that are "color1+line/point/mesh1","color2+line/point/mesh1", and "color1+line/point/mesh2". $\endgroup$
    – hu_rrr
    Apr 12 at 8:35
  • $\begingroup$ Related, see mathematica.stackexchange.com/questions/49202/… $\endgroup$
    – Acus
    Apr 12 at 8:54
  • $\begingroup$ I have understood, thank you very much!!! $\endgroup$
    – hu_rrr
    Apr 12 at 9:06

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.