# Exporting image and scale

Let us say I have a plot, for example that one:

Plot[x^2,{x,0,5},AspectRatio->5]


and I would like to export it as a PDF in such a way that if I print the PDF in a A4 format (for instance), 1 "unit" on the plot will correspond to 1cm on the A4. So the $$x$$-axis above should measure exactly 5cm when printed on an A4. The curve can be rasterized.

Is there an accurate and robust way to do this?

PS: This can be useful if you want to print a map at a given scale, or plans, etc.

ImageSize has a form (still undocumented)

 ImageSize -> a -> b


to have a user units correspond to b printer's points.

So you can use

cm = 72/2.54;
Plot[x^2, {x, 0, 5}, AspectRatio -> Automatic, ImageSize -> 1 -> cm]


A paper ruler:

metricruler = Plot[0, {x, 0, 20},
AspectRatio -> Automatic, AxesOrigin -> {0, 0},
PlotRangePadding -> 0, PlotStyle -> None, Axes -> {True, False},
ImageSize -> 1 -> cm]


If you export as PDF and print you should get a paper ruler.

• Dude! Woah! This is cool. What are the limitations of the units/inputs for b, in this case?? Wow!! – CA Trevillian Jul 25 '19 at 4:16
• @CATrevillian, i don't know of any limitations for b - any number should work, I think. – kglr Jul 25 '19 at 4:23
• Oh I just suck at actually reading and did a skim, I see now you defined cm in the previous step. Still though! This is super awesome. I had thought you called an Entity or something like that. – CA Trevillian Jul 25 '19 at 4:24
• Just made the test: it's almost perfect, the rule measured about 20.07cm instead of 20cm. But the discrepancy might be due to the PDF reader and the printing procedure. In the next days, I'll try to adapt this helpful feature to generate an A4 or A3 pdf. Thanks! – anderstood Jul 25 '19 at 8:56

Looking at the documentation pages of FontSize and ImageSize, we see that both are given in printer's points, with 72dpi assumed.

This means that you can determine the appropriate settings like this:

$$\text{size for MMA}=\text{size in cm}\;\cdot72/2.54$$

As an example, the following produces a PDF with a size of an A4 paper, and the plot label is 1cm high:

Export[
"test.pdf",
Plot[
x^2, {x, 0, 5},
PlotLabel -> "qfA",
AspectRatio -> 5,
LabelStyle -> FontSize -> 1*72/2.54,
ImageSize -> {21, 29.7}/2.54*72
]
]

• Mmh, I don't have MMA at hand right now, but I think this would only work if there is no axes or label. For example if the plot label is as long as the plot, 1cm on the plot will roughly correspond to .5cm on the paper. But I'll check. Thanks anyway. – anderstood Jul 22 '19 at 20:08
• I'm not sure I get what you mean - The code in the answer generates a document of the desired size, and it has both a label and axes – Lukas Lang Jul 23 '19 at 7:25
• I meant that your suggestion is not just "plot"-dependent: it is based on the scale of the whole graphic (plot + axes + ticks + labels + ...), not just on the surface covered by the coordinate system. Compare plot1 and plot2 with: plot2= Plot[ 5*x, {x, 0, 5}, PlotLabel -> "qfA", AspectRatio -> 5, LabelStyle -> FontSize -> 1*72/2.54, ImageSize -> {6, 29.7}/2.54*72 ] and plot2= Plot[ 5^3*x, {x, 0, 5^3}, PlotLabel -> "qfA", AspectRatio -> 5, LabelStyle -> FontSize -> 1*72/2.54, ImageSize -> {6, 29.7}/2.54*72 ]. – anderstood Jul 24 '19 at 7:59
• Ahh, so you want 1 unit of the plot to equal 1cm? I thought you meant the number 1 in the tick mark for some (strange) reason – Lukas Lang Jul 24 '19 at 8:16
• Indeed. I'll edit my question to make it more clear. – anderstood Jul 24 '19 at 9:30