jayw
(Jay Warendorff)
1
How can this code be modified to position the darker rectangle in the upper right corner of the lighter rectangle? Thanks.
Overlay[{
Graphics[{Opacity[.4], Rectangle[]}, ImageSize -> .2 {300, 787},
ImagePadding -> 0, PlotRangePadding -> 0],
Graphics[{Opacity[.2], Rectangle[]}, ImagePadding -> 0,
PlotRangePadding -> 0]},
Alignment -> {1, 1}]
zachb
(Zach Bjornson)
2
Inset will probably be easier to work with:
Graphics[{Opacity[.4], Rectangle[],
Inset[Graphics[{Opacity[.2], Rectangle[]}], {1, 1}, {1, 1}, 0.2]},
ImageSize -> 300, ImagePadding -> 0, PlotRangePadding -> 0]
brettc
(Brett Champion)
3
The small square has padding from the explicit image width and height:
Overlay[{
Graphics[{Opacity[.4], Rectangle[]}, ImageSize -> .2 {300, 787},
ImagePadding -> 0, PlotRangePadding -> 0, Background -> Red],
Graphics[{Opacity[.2], Rectangle[]}, ImagePadding -> 0,
PlotRangePadding -> 0]},
Alignment -> {1, 1}]
Using an Automatic setting, or at least sizes that match the aspect ratio of the graphic, will work:
Overlay[{
Graphics[{Opacity[.4], Rectangle[]},
ImageSize -> {0.2*300, Automatic}, ImagePadding -> 0,
PlotRangePadding -> 0, Background -> Red],
Graphics[{Opacity[.2], Rectangle[]}, ImagePadding -> 0,
PlotRangePadding -> 0]}, Alignment -> {1, 1}]