Skip to main content
added 237 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is wrapped by Inset:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 ImageSize -> {400, 150}]

output

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3]

ImageCrop@ImageCrop@% // ImageDimensions

output

{300, 100}

Unfortunately with this workaround we loose the ability to position inset relative to the coordinates in the intrinsic coordinate system of its Graphics object as well as relative to Scaled coordinates inside its plotting range. :(

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is wrapped by Inset:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 ImageSize -> {400, 150}]

output

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3]

ImageCrop@ImageCrop@% // ImageDimensions

output

{300, 100}

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is wrapped by Inset:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 ImageSize -> {400, 150}]

output

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3]

ImageCrop@ImageCrop@% // ImageDimensions

output

{300, 100}

Unfortunately with this workaround we loose the ability to position inset relative to the coordinates in the intrinsic coordinate system of its Graphics object as well as relative to Scaled coordinates inside its plotting range. :(

added 604 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is wrapped by Inset:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 AspectRatioImageSize -> 1/3]{400, 150}]

outputoutput

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3, 
 ImagePadding -> None, ImageMargins -> 0, ImageSize -> {400, 150}]3]

ImageCrop@ImageCrop@% // ImageDimensions

outputoutput

{300, 100}

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is wrapped by Inset:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 AspectRatio -> 1/3]

output

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3, 
 ImagePadding -> None, ImageMargins -> 0, ImageSize -> {400, 150}]

ImageCrop@ImageCrop@% // ImageDimensions

output

{300, 100}

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is wrapped by Inset:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 ImageSize -> {400, 150}]

output

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3]

ImageCrop@ImageCrop@% // ImageDimensions

output

{300, 100}
added 604 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is inside ofwrapped by Inset.:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 AspectRatio -> 1/3]

output

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3, 
 ImagePadding -> None, ImageMargins -> 0, ImageSize -> {400, 150}]

ImageCrop@ImageCrop@% // ImageDimensions

output

{300, 100}

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is inside of Inset.

A minor addition to the other answers.

As it is recently uncovered by Carl Woll, ImageSize accepts undocumented form

ImageSize -> Automatic -> {width, height}

which allows you to specify the width and height of the plot range directly.

This option has higher precedence than AspectRatio:

gr = Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
  ImageSize -> Automatic -> {300, 100}, AspectRatio -> 1, Frame -> True, 
  Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

It can be used in combination with AspectRatio:

Graphics[{Lighter@Blue, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}, 
 ImageSize -> Automatic -> {Automatic, 100}, AspectRatio -> 1/3, Frame -> True, 
 Background -> GrayLevel[0.8], FrameStyle -> Opacity[0]]

ImageCrop[%] // ImageDimensions

output

{300, 100}

The only (but crucial!) drawback is that this undocumented form doesn't play well when Graphics is wrapped by Inset:

Graphics[{Inset[gr, {0, 0}, {0, 0}, Automatic]}, Background -> LightGreen, 
 AspectRatio -> 1/3]

output

A workaround is to wrap Graphics by Pane, Framed, Text or ExpressionCell:

Graphics[{Inset[Text[gr]]}, Background -> LightGreen, AspectRatio -> 1/3, 
 ImagePadding -> None, ImageMargins -> 0, ImageSize -> {400, 150}]

ImageCrop@ImageCrop@% // ImageDimensions

output

{300, 100}
added 4 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading