I executed this command:
RegionPlot[x > 2 && x < 3 && y > 2 && y < 3, {x, 0, 4}, {y, 0, 4}]
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?
I executed this command:
RegionPlot[x > 2 && x < 3 && y > 2 && y < 3, {x, 0, 4}, {y, 0, 4}]
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?
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]
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]
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]}]
Related Q/A: Different Boundary Style on each edge of 3D Plot
Graphicsprimitives, using appropriately styledRectangleandLineobjects. MUCH easier! – MarcoB Jan 24 '21 at 07:26