4

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.

imida k
  • 4,285
  • 9
  • 17
  • 1
    does this give what you need: Graphics[{Circle[{0, 0}, 1], Circle[{1, 0}, 1], Circle[{2, 0}, 1]}, ImageSize -> 1 -> 70]? – kglr Jun 05 '23 at 23:15
  • 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. – imida k Jun 05 '23 at 23:17

1 Answers1

4

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

kglr
  • 394,356
  • 18
  • 477
  • 896