3

I executed this command:

RegionPlot[x > 2 && x < 3 && y > 2 && y < 3, {x, 0, 4}, {y, 0, 4}]

enter image description here

I would like the top and right sides of the square to be dashed lines and the bottom and left sides of the square to be thick, solid lines. How do I do this?

mont2223
  • 31
  • 1

1 Answers1

5

One possible way is to use the options MeshFunctions and Mesh:

RegionPlot[x >= 2 && x <= 3 && y >= 2 && y <= 3, {x, 0, 4}, {y, 0, 4}, 
 PlotPoints -> 100, 
 BoundaryStyle -> None, 
 PlotStyle -> Opacity[.3, Yellow],
 MeshFunctions -> {# &, #2 &}, 
 Mesh -> {{{2, Opacity[1, Red]}, {3, Opacity[1, Cyan]}}, 
  {{2, Opacity[1, Purple]}, {3, Opacity[1, Blue]}}},
 BaseStyle -> Thick]

enter image description here

An alternative way is to use Graphics (as suggested by MarcoB in comments):

Graphics[{FaceForm[Opacity[.3, Yellow]], Rectangle[{2, 2}, {3, 3}], 
  Thick, MapThread[List, {{Red, Cyan, Purple, Blue}, Line /@ 
   {{{2, 2}, {2, 3}}, {{3, 2}, {3, 3}}, {{2, 2}, {3, 2}}, {{2, 3}, {3, 3}}}}]},
 PlotRange -> {{0, 4}, {0, 4}}, Frame -> True]

enter image description here

A more convenient way to avoid listing of line coordinates:

{lines, polygon} = MeshPrimitives[
     BoundaryDiscretizeRegion[Rectangle[{2, 2}, {3, 3}], 
      MaxCellMeasure -> Infinity], #] & /@ {1, 2};

Graphics[{FaceForm[Opacity[.3, Yellow]], polygon, Thick, MapThread[List, {{Purple, Cyan, Blue, Red}, lines}]}, PlotRange -> {{0, 4}, {0, 4}}, Frame -> True]

same picture

SeedRandom[1];
randompolygon = RandomPolygon[10];

Graphics[{FaceForm[Opacity[.25, Yellow]], randompolygon, Thick, {RandomColor[], Line @ #} & /@ Partition[Append[#, First @ #] & @ randompolygon[[1]], 2, 1]}]

enter image description here

Related Q/A: Different Boundary Style on each edge of 3D Plot

kglr
  • 394,356
  • 18
  • 477
  • 896