3
$\begingroup$
Row[Table[Graphics[Rectangle[{0, 0}, {2^k, 1}]], {k, 0, 5}]]

yields

enter image description here

However, I'd like uniform scaling of the rectangles, i.e., each rectangle should look twice the width (but same height) as its predecessor. How can I force "absolute sizing" here?

Second, how can I align the bottoms of the rectangles? I tried inserting Alignment->Bottom in several spots, none of which worked.

$\endgroup$
1
  • $\begingroup$ I also find it strange that it is keeping the widths constant, but scaling the heights even though it is the widths that are increasing with k. $\endgroup$
    – JohnD
    Nov 9 '12 at 19:42
7
$\begingroup$

Row will resize anything that doesn't already have a size attribute set. By setting the imageheight for each graphics object but keeping the width Automatic, you get what you are looking for:

Row[Table[Graphics[Rectangle[{0, 0}, {2^k, 1}], ImageSize -> {Automatic, 25}, PlotRangePadding -> None], {k, 0, 5}]]

enter image description here

Since they are all the same height, they are all automatically aligned properly. If they weren't, I couldn't get Row to align them properly, but Grid did the trick easily.

Grid[{Table[Graphics[Rectangle[{0, 0}, {2^k, 1}],PlotRangePadding -> None], {k, 0, 5}]},  Alignment -> {Left, Bottom}]

gives this: enter image description here

$\endgroup$
5
  • 2
    $\begingroup$ My experience is that you can also control the spacing between elements a lot better with Grid than with Row. (Are we all agreed that GraphicsGrid is a trainwreck?) $\endgroup$
    – user4368
    Nov 9 '12 at 19:56
  • 2
    $\begingroup$ Yes, GraphicsGrid = trainwreck with maximal carnage, IMO. $\endgroup$
    – JohnD
    Nov 9 '12 at 20:52
  • $\begingroup$ Jason, I still don't get why the first rectangle won't cooperate: Grid[{Table[Graphics[Rectangle[{0, 0}, {2^-k, 1}], PlotRangePadding -> None], {k, 0, 5}]}, Alignment -> {Left, Bottom}] $\endgroup$
    – JohnD
    Nov 9 '12 at 20:55
  • 1
    $\begingroup$ @texasAUtiger, from what I can tell, Grid and Row will resize anything that doesn't have its ImageSize set already. So I would still set them so they all have the same height: Grid[{Table[Graphics[Rectangle[{0,0},{2^(-k),1}],PlotRangePadding->None,ImageSize->{Automatic,25}],{k,0,5}]},Alignment->{Left,Bottom}] $\endgroup$
    – user4368
    Nov 9 '12 at 21:18
  • $\begingroup$ Jason, try e.g. Row[(*list*), Spacer[5]] $\endgroup$
    – Mr.Wizard
    Nov 10 '12 at 9:12
2
$\begingroup$

You could specify the PlotRange explicitly as follows:

Row[Table[
  Graphics[Rectangle[{0, 0}, {2^k, 1}], 
   PlotRange -> {{0, 2^5}, {0, 1}}], {k, 0, 5}]]

example

$\endgroup$
1
  • $\begingroup$ I'd need to avoid the large gaps of white space in this solution. $\endgroup$
    – JohnD
    Nov 9 '12 at 19:43

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.