2
$\begingroup$
fadingPrimitive[size_, formula_, c_] :=
 DensityPlot[
  Max[0, formula],
  {x, -size, size}, {y, -size, size},
  ColorFunction -> (Opacity[#, c] &),
  Frame -> False];

smoothlyFadingColorDisk[r_, c_] :=
 fadingPrimitive[r, r - Sqrt[x^2 + y^2], c];

smoothlyFadingColorRing[rs_, rb_, c_] :=
 fadingPrimitive[rs + rb, rs - Abs[rb - Sqrt[x^2 + y^2]], c];

Up to this point everything works nice. The image size is exactly as large as the actual graphics:

smoothlyFadingColorDisk[1, Purple]

enter image description here

smoothlyFadingColorRing[0.25, 1.25, Blue]

enter image description here

But when I try to combine them, the image size suddenly gets much larger than the actual graphics:

Graphics[{
 Inset[smoothlyFadingColorDisk[1, Purple]],
 Inset[smoothlyFadingColorRing[0.25, 1.25, Blue]]}]

enter image description here

I tried ImageSize->Scaled[1], ImageSize->Full, ImageSize->All, ImageSize->Automatic - all fail or even make the disproportion even greater.

Show[
 smoothlyFadingColorRing[0.25, 1.25, Blue],
 smoothlyFadingColorDisk[1, Purple]]

This works as expected, but I'd rather avoid show: I want to be able to use Insets to be able to reposition the graphics, and it seems I can't use Insets with Show.

Why does this happen? How to set this straight? Thanks in advance!

$\endgroup$
1
  • 1
    $\begingroup$ closely related: 73522 $\endgroup$
    – Kuba
    Feb 12, 2015 at 9:11

1 Answer 1

6
$\begingroup$

The coordinate system of the enclosing Graphics is completely independent of the one used in the Inset. So you have to specify in Inset how it is to be positioned and sized relative to the enclosing Graphics. In your case, you just want to modify the size. That's the fourth argument in Inset (it's optional), so the code looks like this:

Graphics[{Inset[smoothlyFadingColorDisk[1, Purple], Automatic, 
   Automatic, Scaled[1]], 
  Inset[smoothlyFadingColorRing[0.25, 1.25, Blue], Automatic, 
   Automatic, Scaled[1]]}]

shades

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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