4
$\begingroup$

I have:

Graphics[{
  LightBlue, 
  Polygon[{{2/3, 0}, {2, 0}, {2, 1}, {3, 1}, {3, 3}, {2/3, 0}}],
  EdgeForm[Black], White, Opacity[0],
  Rectangle[{0, 0}, {1, 1}],
  Rectangle[{1, 0}, {2, 1}],
  Rectangle[{1, 1}, {2, 2}],
  Rectangle[{2, 1}, {3, 2}],
  Rectangle[{2, 2}, {3, 3}],
  Red, Thick, Line[{{2/3, 0}, {3, 3}}]
  },
 Axes -> True]

But my red line does not show up. Could it have something to do with the way I constructed my rectangles. It is last, so I expected it to be on the top layer.

Maybe I should ask is there a way to use the Rectangle and Polygon command with no filling?

Update (Thanks to Rahul): Excellent advice. This worked.

Graphics[{
  LightBlue, 
  Polygon[{{2/3, 0}, {2, 0}, {2, 1}, {3, 1}, {3, 3}, {2/3, 0}}],
  {FaceForm[None], EdgeForm[Black],
   Rectangle[{0, 0}, {1, 1}],
   Rectangle[{1, 0}, {2, 1}],
   Rectangle[{1, 1}, {2, 2}],
   Rectangle[{2, 1}, {3, 2}],
   Rectangle[{2, 2}, {3, 3}]},
  Red, Thick, Line[{{2/3, 0}, {3, 3}}]
  },
 Axes -> True]

enter image description here

$\endgroup$
  • 4
    $\begingroup$ It's because you set Opacity[0], so the line is completely invisible. To disable filling, use FaceForm[None] instead. $\endgroup$ – Rahul Dec 5 '15 at 20:42
  • $\begingroup$ @Rahul Thanks for the help. I learned a lot with the new FaceForm[None] command. $\endgroup$ – David Dec 5 '15 at 21:35
4
$\begingroup$
Graphics[
 {
  LightBlue,
  (* valid until the next color spec *)
  Polygon[{{2/3, 0}, {2, 0}, {2, 1}, {3, 1}, {3, 3}, {2/3, 0}}],

  EdgeForm[Black], White,
  Opacity[0],
  (* valid until the next opacity spec *)
  Rectangle[{0, 0}, {1, 1}],
  Rectangle[{1, 0}, {2, 1}],
  Rectangle[{1, 1}, {2, 2}],
  Rectangle[{2, 1}, {3, 2}],
  Rectangle[{2, 2}, {3, 3}],

  Red, Thick, 
  (* restore normal opacity *)
  Opacity[1],
  Line[{{2/3, 0}, {3, 3}}],
  },
 Axes -> True]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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