I know there is a Rectangle[]
function, but it is always filled with some color. What I need is a rectangle, which is empty inside (only it's boundaries visible). I just need to overlay it on plotted function to indicate some of it's area.
2 Answers
Use FaceForm[]
to define the polygon's filling as empty. You set the polygon's outline color with EdgeForm[color]
Graphics[{EdgeForm[{Thick, Blue}], FaceForm[], Rectangle[]}]
or slightly more complex:
Graphics[
{
EdgeForm[{Thick, Hue[Random[]]}],
FaceForm[],
Rectangle[#, # + {4, 4}]
} & /@ RandomReal[{-10, 10}, {30, 2}]
]
Just for completeness, it is hardly difficult to do this manually:
box[{x_, y_}, {X_, Y_}] :=
Line[{{x, y}, {x, Y}, {X, Y}, {X, y}, {x, y}}];
Graphics[{
{Red, Rectangle[{0, 0}, {1, 3}]},
{Blue, Rectangle[{2, 1}, {4, 2}]},
{Thick, box[{0, 0}, {1, 3}]}
}]
Manual control allows for customizations:
box2[{x_, y_}, {X_, Y_}] :=
MapIndexed[
{Arrowheads[Sqrt[#2]/30`], Arrow@#} &,
Partition[{{x, y}, {x, Y}, {X, Y}, {X, y}, {x, y}}, 2, 1]
]
Graphics[{
{Red, Rectangle[{0, 0}, {1, 3}]},
{Blue, Rectangle[{2, 1}, {4, 2}]},
{Thick, box2[{0, 0}, {1, 3}]}
}, ImagePadding -> 10]
Line
yet? $\endgroup$