4
$\begingroup$

On my MMA, I apply the options

SetOptions[$FrontEnd, 
 GraphicsBoxOptions -> {BaseStyle -> Magnification -> 72/120}]

Then I can assure the output Graphics has the width specified in the ImageSize option.

For example the code

Graphics[Circle[{0, 0}, 1], ImageSize -> 140]

enter image description here

creates 140-pixel wide Graphics.

To create graphics with two or three overlapping circles of the same size, I can do the following.

Graphics[{Circle[{0, 0}, 1],
  Circle[{1, 0}, 1]}, ImageSize -> 210]

Graphics[{Circle[{0, 0}, 1],
  Circle[{1, 0}, 1],
  Circle[{2, 0}, 1]
  }, ImageSize -> 280]

enter image description here

Notice that we had to calculated the value of ImageSize manually, to write the code.
The calculation was not that difficult, (140 * 1/2 *3 = 210, and 140 * 1/2 * 4 = 280) so that it was possible to do with mental arithmetic and elementary school level knowledge of geometry.

But the example above was in fact very easy. It will be difficult to calculate ImageSize in a Graphics where figures of various sizes and shapes mixed.

In this sense, it would be very nice if we had an (imaginary) option Pixels per Graphics Unit Length like the one below. See the following imaginary screenshot :

enter image description here

Quetsion :
Is it possible to create Graphics of any size that I want, with the way explained above? I mean using Pixels per Graphics Unit Length concept.

$\endgroup$
2
  • 1
    $\begingroup$ does this give what you need: Graphics[{Circle[{0, 0}, 1], Circle[{1, 0}, 1], Circle[{2, 0}, 1]}, ImageSize -> 1 -> 70]? $\endgroup$
    – kglr
    Commented Jun 5, 2023 at 23:15
  • $\begingroup$ Wow! it works! Thank you very much! Simple and wonderful! You can write it as an answer If you want to be accepted as an answer. $\endgroup$
    – imida k
    Commented Jun 5, 2023 at 23:17

1 Answer 1

4
$\begingroup$

Use the syntax ImageSize -> 1 -> np to make 1 unit in user units to be rendered as np printer points:

g1 = Graphics[{AbsoluteThickness[10], Green, Circle[{0, 0}, 1]}, 
   ImageSize -> 1 -> 70, 
   PlotRangePadding -> 0, ImagePadding -> 5];

g2 = Graphics[{AbsoluteThickness[5], Red, Circle[{0, 0}, 1], Circle[{1, 0}, 1]},
   ImageSize -> 1 -> 70, 
   PlotRangePadding -> 0, ImagePadding -> 5];

g3 = Graphics[{AbsoluteThickness[1/2], Black, Circle[{0, 0}, 1], 
      Circle[{1, 0}, 1], Circle[{2, 0}, 1]}, 
   ImageSize -> 1 -> 70, 
   PlotRangePadding -> 0, ImagePadding -> 5];

Overlay[{g1, g2, g3}, Alignment -> {Left, Bottom}]

enter image description here

$\endgroup$
6
  • $\begingroup$ That syntax was new to me! Is it documented anywhere? (+1) $\endgroup$
    – MarcoB
    Commented Jun 6, 2023 at 0:58
  • $\begingroup$ @MarcoB, afaik it is still not documented. It has been used a number of times on this site; but I can't locate the relevant Q/As. $\endgroup$
    – kglr
    Commented Jun 6, 2023 at 1:14
  • $\begingroup$ found a few: Exporting image and scale, Maintaining shape size while rotating in GraphicsGrid $\endgroup$
    – kglr
    Commented Jun 6, 2023 at 1:22
  • $\begingroup$ Awesome, thank you! $\endgroup$
    – MarcoB
    Commented Jun 6, 2023 at 10:58
  • 1
    $\begingroup$ Just for the record, np is in points. $\endgroup$
    – ihojnicki
    Commented Jun 6, 2023 at 19:03

Your Answer

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

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