# How to make Inset graphics maintain relative sizes when combined

I am learning a little about Inset, but after trying all options, I can't get this to work. I need to inset separately made Graphics2D objects, into one main Graphics2D but have them show up there with same relative sizes they had on their own. I use the Axes of the main Graphics as measuring stick yard to check that this is true.

For example, if I make disk of radius 1, and rectangle of width 6, and then Inset them to main Graphics, I expect them to show there with same relative sizes. Disk will still have radius 1 and the rectangle will still have width 6, but now when looking at the main Axes.

Here is an example:

 g1 = Graphics[{LightGray, Disk[{0, 0}, 1]}, AspectRatio -> Automatic];


.ps the plot above is same code, but added Axes->True to it for illustration. I do not use Axes in the separate Graphics. But use Axes in the main Graphics.

 g2 = Graphics[{Opacity[.5], Blue, Rectangle[{-3, -1}, {3, 1}]}, AspectRatio -> Automatic];


Now I want to insert the disk at origin of main Graphics, and insert the rectangle at location (2,2). But this is what happens when I do

Graphics[
{Inset[g1, {0, 0}],
Inset[g2, {2, 2}]
}, Axes -> True, PlotRange -> {{-6, 6}, {-4, 4}}, AspectRatio -> Automatic]


Looking at the above, the disk now shows with radius 2, and the rectangle became square. (relative the Axes of the main graphics). What I'd like to get is this: (did this manually, by adjusting the image sizes one by one after inserting)

I tried many options, but can't get the effect I want. Tried Scaled and changing aspect ratio setting, but did not help.

What is the correct way to inset graphics, so they show up with same axes limits/sizes as in the original graphics? but now will be relative to the main Graphics.

• Strangely when I try to reproduce your code my rectangle do not become a square but stays a rectangle (with its correct aspect ratio.) (OSX10.9.5, v10.0.2) – SquareOne Feb 8 '15 at 17:21
• In your graphic, the final disk radius is not 2 but 3. – SquareOne Feb 8 '15 at 17:23

This seems to be what you want:

Graphics[
Inset[##, {0, 0}, #2 - # & @@ First@PlotRange@#] &,
{{g1, g2}, {{0, 0}, {2, 2}}}
],
Axes -> True,
PlotRange -> {{-6, 6}, {-4, 4}}
]


For precision I believe one will need to set PlotRangePadding -> 0 and ImagePadding -> 0 in each of the inset Graphics.

• thanks, but this is not really what I meant. You just used the g1 axes instead of the master graphics axes I want to combine many graphics into. May be my example was too simple. I'll add g2 to make it more clear what I mean. i.e. I'll have Disk and Rectangle, each separate graphics2D, then want to combine them into one Graphics, using Inset, and have them come out with same relative sizes as each originally. Will update my question soon to make this clear. in few minutes... – Nasser Feb 8 '15 at 11:43
• @Nasser Looking forward to your update... – Mr.Wizard Feb 8 '15 at 11:44
• @Nasser I took another shot at this, hopefully with a bit more success. – Mr.Wizard Feb 8 '15 at 12:48
• thanks, yes, this is exactly what I wanted. You are right, PlotRangePadding -> 0 is needed in the separate graphics for more accurate positioning. I'll test it with more graphics now as well. – Nasser Feb 8 '15 at 12:53
• Did not know that PlotRange can be used as a function (PlotRange[somegraphics]) ... :) Any refs ? – SquareOne Feb 8 '15 at 18:26
g1 = Graphics[{LightGray, Disk[{0, 0}, 1]}, AspectRatio -> Automatic];
g2 = Graphics[{Opacity[.5], Blue, Rectangle[{0, 0}, {1, .5}]}, AspectRatio -> Automatic];
Graphics[
{
Inset[g1, {0, 0}, {0, 0}, Scaled[{.35, 1}]],
Inset[g2, {0, 2}, {0, 0}, Scaled[{.35, 1}]]
},
Axes -> True,
PlotRange -> {{-6, 6}, {-4, 4}},
AspectRatio -> Automatic
]

• Welcome to Mathematica Stack Exchange. Unfortunately this is not the result that Nasser desires; here both objects appear with the same width whereas the rectangle should be much wider. – Mr.Wizard Feb 8 '15 at 19:22
• ....Rectangle[{0, 0}, {1, .333}]}, ..... Inset[g1, {0, 0}, {0, 0}, Scaled[{.175, 1}]], Inset[g2, {-1, 1}, {0, 0}, Scaled[{.35 + .175, 1}]] ..... – dofuuu Feb 8 '15 at 21:30