Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Did you try a Line yet? – Yves Klett Sep 11 '12 at 19:57
Was just about to start doing it, but now I see Sjoerd's answer is exactly what I need. – alex Sep 11 '12 at 20:17
up vote 23 down vote accepted

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:

     EdgeForm[{Thick, Hue[Random[]]}], 
     Rectangle[#, # + {4, 4}]
   } & /@ RandomReal[{-10, 10}, {30, 2}]

Mathematica graphics

share|improve this answer

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}}];

  {Red, Rectangle[{0, 0}, {1, 3}]},
  {Blue, Rectangle[{2, 1}, {4, 2}]},
  {Thick, box[{0, 0}, {1, 3}]}

Mathematica graphics

Manual control allows for customizations:

box2[{x_, y_}, {X_, Y_}] :=
  {Arrowheads[Sqrt[#2]/30`], Arrow@#} &,
  Partition[{{x, y}, {x, Y}, {X, Y}, {X, y}, {x, y}}, 2, 1]

  {Red, Rectangle[{0, 0}, {1, 3}]},
  {Blue, Rectangle[{2, 1}, {4, 2}]},
  {Thick, box2[{0, 0}, {1, 3}]}
 }, ImagePadding -> 10]

Mathematica graphics

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.