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 am trying to obtain a thin frame around the bars in this chart but it's proving rather tricky. Can anyone suggest a solution?

size = {3, 12, 8, 0.5, 7, 5, 6, 7, 3, 4, 2};

bar[i_] := Inset[Graphics[{EdgeForm[{Thin, Black}],
    FaceForm@LightBlue, Rectangle[{0, -1/2}, {size[[i]], 1/2}]},
   PlotRange -> {{0, size[[i]]}, {(-1/2), 1/2}}],
  {1, -(Length[size] - i + .5)}, {Left, Center}, size[[i]]];

Graphics[{LightYellow, Rectangle[{0, 0}, {15, -(Length[size] + 1)}],
  Array[bar, Length[size]]},
 PlotRange -> {{0, 15}, {0, -(Length[size] + 1)}}]

enter image description here

A second version has the same problem:

bar[i_] := Inset[Graphics[{LightBlue,
    Rectangle[{0, -1/2}, {size[[i]], 1/2}]},
   PlotRange -> {{0, size[[i]]}, {(-1/2), 1/2}},
   Frame -> True, FrameTicks -> None, ImagePadding -> 0],
  {1, -(Length[size] - i + .5)}, {Left, Center}, size[[i]]];

Edit

Thanks to Heike's comment I have something I can use:

size = {3, 12, 8, 0.5, 7, 5, 6, 7, 3, 4, 2};

bar[i_] := Rectangle[{1, -(i - 1)}, {size[[Length[size] + 1 - i]] + 1, -i}];

Graphics[{LightYellow, Rectangle[{0, 0}, {15, -(Length[size] + 1)}],
  EdgeForm[{Thin, Black}], FaceForm@LightBlue,
  Array[bar, Length[size]]},
 PlotRange -> {{0, 15}, {0, -(Length[size] + 1)}}]

enter image description here

share|improve this question
4  
Is there any particular reason why you're using Inset to place the individual bars in the yellow rectangle instead of using Rectangles directly? –  Heike May 15 '12 at 13:03

1 Answer 1

I cannot remember the solution to this problem, but I will point out that at the right ImageSize the lines are not clipped:

Graphics[{LightYellow, Rectangle[{0, 0}, {15, -(Length[size] + 1)}], 
  Array[bar, Length[size]]}, 
 PlotRange -> {{0, 15}, {0, -(Length[size] + 1)}}, 
 ImageSize -> {Automatic, 450}]

Mathematica graphics

share|improve this answer
    
Okay, I think I remember the solution. A somewhat similar problem affects BarChart, and someone solved it by creating one big polygon for all the bars and drawing Lines over it. –  Mr.Wizard May 15 '12 at 13:22
    
@ Mr.Wizard - Did you work out that 450 was the right image height by trial and error? I see 150 nearly works but 650 fails more. –  Chris Degnen May 16 '12 at 8:26
    
@Chris yes, I simply drag-resized the graphic until it looked good. I saw that you have a working method so I didn't try to reimplement the Polygon/Line solution. –  Mr.Wizard May 16 '12 at 12:12

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.