9
$\begingroup$

I have wondered more and more often lately how the size of an image is handled when displayed or exported. The documentation implies that the via ImageSize the size could be set in printer points (per inch). That does however not correspond with the displayed graphics (for instance ImageSize-> {72 1, 72 1 }) does not render a generic plot with the expected size of one inch square. (UI magnification at 100%)

I am using Mathematica 9 on OS X 10.9 and usually use .eps for exporting plots (since .pdf export doesn't really work that well with fonts and all)

$\endgroup$
4
  • $\begingroup$ This is Export-related only (but duplicate-ish): mathematica.stackexchange.com/q/5442/131. I guess sizes on-screen are another animal entirely. $\endgroup$
    – Yves Klett
    Commented Nov 19, 2013 at 15:06
  • $\begingroup$ ImageSize only changes the display. To actually change the size of the image in pixels (for instance when you export), use ImageResize. Then you can specify exactly how big/small you want it. $\endgroup$
    – bill s
    Commented Nov 19, 2013 at 15:29
  • 2
    $\begingroup$ For exporting to PDF, I sometimes need to use the workaround cm = 72/2.54; Export["file.pdf", Show[graphics, ImageSize -> 10 cm]]. This gives a size of precisely 10 cm. $\endgroup$
    – Szabolcs
    Commented Nov 19, 2013 at 17:50
  • $\begingroup$ Take a look here, some of the ideas may be of use to you. $\endgroup$
    – Szabolcs
    Commented Nov 19, 2013 at 20:48

1 Answer 1

11
$\begingroup$

I export graphics like this:

cm = 72/2.54;
Export["file.pdf", Show[graphics, ImageSize -> 10 cm]]

For some reason Show is required when exporting to PDF, i.e. you can't just use the ImageSize option directly in Export and still get the expected result.


Regarding display on the screen, ImageSize is interpreted as pixels for on-screen display and as PostScript points (1/72 inch) for exporting to printable formats such as PDF. In other words, Mathematica always assumes the display to be a 72 ppi one.

$\endgroup$
12
  • 3
    $\begingroup$ N.B. ImageSize is (documented to be) printer's points whether onscreen or on paper. It just happens that many screens have (or used to have) 72 pixels per inch, and Mathematica uses this as a default instead of the actual resolution, as you noted in your answer in the link. Why it does this, I don't quite know. $\endgroup$ Commented Apr 20, 2014 at 1:14
  • $\begingroup$ @OleksandrR. and Szabolcs, If I understand correctly that means for MMA pp == px is always True? And this is quite fundamental and not mentioned in documentation, right? p.s. There is m cm naming problem. $\endgroup$
    – Kuba
    Commented Feb 11, 2016 at 14:00
  • $\begingroup$ @Kuba what does pp == px mean? $\endgroup$ Commented Feb 11, 2016 at 14:02
  • 1
    $\begingroup$ @Kuba I agree that this doesn't seem right. Sometimes an assumption of 72 dpi is hard-coded and ImageSize uses that assumption; other times there is the ImageResolution option as well. It seems that ImageSize is always supposed to be printer's points, though, even if the front end doesn't know how many pixels that corresponds to. RasterSize is explicitly pixels. $\endgroup$ Commented Feb 11, 2016 at 14:25
  • 1
    $\begingroup$ @Kuba The ImageResolution option can change this 72. It has to be used in Rasterize or Export. Another thing: do not use ImageSize in Export, use it instead as a Graphics option to get the desired result. Export[..., g, ImageSize -> ..., ImageResolution -> ...] is bad. Export[..., Show[g, ImageSize -> ...], ImageResolution -> ...] is good. At least for bitmap formats like PNG. But I don't understand why! $\endgroup$
    – Szabolcs
    Commented Feb 11, 2016 at 14:29

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.