Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
1  
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
add comment

2 Answers

up vote 19 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:

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

Mathematica graphics

share|improve this answer
add comment

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

Mathematica graphics

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]

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

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.