1

I would like to replicate this plot:

Enter image description here

From A parametric model for dark energy.

But how can I add the lines and the grids to the various sections?

Peter Mortensen
  • 759
  • 4
  • 7
Alucard
  • 2,639
  • 13
  • 22

2 Answers2

7
inequalities = {y >= -x,
   y < -x && x >= -.45, 
   5 + 5 x <= y <= -x - 1.1, 
   Min[5 + 5 x, -x] >= y >= -x - 1.1 &&   x <= -.45};

regions = ImplicitRegion[{#}, {{x, -3/2, 0}, {y, -2,   2}}] & /@ inequalities;

labels = {"forbidden", "decelerated", "phantom", "quintessence"};

fillings = {PatternFilling["Diamond", ImageScaled[1/50]],
    HatchFilling[-Pi/4],
    HatchFilling[Pi/2],
    HatchFilling[]};

 legends = SwatchLegend[fillings /. ImageScaled[_] -> ImageScaled[1/4], 
  inequalities, LegendMarkerSize -> 30]

 epilog = MapThread[Text[Style[Framed[#, Background -> White, FrameStyle -> White], 
      16], RegionCentroid @ #2, Center] &, {labels, regions}];

 RegionPlot[Evaluate @ regions,
  PlotRange -> {{-3/2, 0}, {-2, 2}},
  ImageSize -> Large,
  BoundaryStyle -> Directive[Thick, Black],
  Epilog -> epilog,
  PlotLegends -> legends,
  PlotStyle -> Thread[Directive[Black, fillings]]]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
3

For versions before 12.1, we can use MeshFunctions and Mesh to get a similar look:

inequalities = {y >= -x,
   y < -x && x >= -.45, 
   5 + 5 x <= y <= -x - 1.1, 
   Min[5 + 5 x, -x] >= y >= -x - 1.1 && x <= -.45};

regions = ImplicitRegion[{#}, {{x, -3/2, 0}, {y, -2, 2}}] & /@ inequalities;

labels = {"forbidden", "decelerated", "phantom", "quintessence"};

meshfunctions = {{4 # + 3/2 #2 &, 3/2 #2 - 4 # &}, {# + #2 &}, {# &}, {# - #2 &}};

meshes = {{80, 100}, 60, 30, 50};

epilog = MapThread[Text[Style[Framed[#, Background -> White, FrameStyle -> White], 14], RegionCentroid @ #2, Center] &, {labels, regions}];

rp = Show[MapThread[ RegionPlot[#, PlotRange -> {{-3/2, 0}, {-2, 2}}, MeshFunctions -> #2, Mesh -> #3, MeshStyle -> Darker@Gray, ImageSize -> 400, BoundaryStyle -> Directive[Thick, Black], PlotStyle -> None] &, {regions, meshfunctions, meshes}], Epilog -> epilog]

enter image description here

Adding a hatch-filled legend requires additional work: We can create RegionPlots with desired hatching patterns using MeshFunctions and Mesh as above and use them as legend markers making use of the (undocumented) option "LegendItem" for LineLegend:

hatchLegend = RegionPlot[True, {x, 0, 1}, {y, 0, 1},
    Frame -> True, 
    FrameTicks -> False, 
    PlotRange -> {{0, 1}, {0, 1}}, 
    ImagePadding -> 1, 
    PlotRangeClipping -> False,
    MeshFunctions -> #,
    Mesh -> #2, 
    MeshStyle -> Directive[AbsoluteThickness[1], #3], 
    ImageSize -> 30, 
    FrameStyle -> Directive[AbsoluteThickness[1], Black], 
    PlotStyle -> None] &;

legenditems = MapThread[hatchLegend, {ReplacePart[{1} -> {# + #2 &, #2 - # &}] @ meshfunctions, {10, 10, 7, 10}, ConstantArray[Darker @ Gray, 4]}];

legend = LineLegend[{White, Gray, Gray, Gray}, inequalities, "LegendItem" -> legenditems, LegendMarkerSize -> {20, 20}];

Legended[rp, legend]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896