Makie: PDF paper size (or MadiaBox)?

How do you specify the paper size of the PDF image? Alternatively, how do you control the physical size of the axes? I must be fundamentally misunderstanding how the sizing of the plot works.

In the example at the end of this massage, I specify size both for Figure() and save() to be 100 × 80 mm but the paper size (MediaBox) of the resultant PDF is 211.7 × 158.7 mm, which is 600 × 450 pt. (You can view this information in the “Properties” menu of Adobe Reader, or by clicking on the “i” button on Preview. The PDF file also includes the statement /MediaBox [ 0 0 600 450 ].)

[Edit: It turns out that the version of Makie I was using didn’t support size, which was the primary reason why the paper size didn’t change. See below for details.]

As a result, the text is too small and lines are too thin.

[I’m not asking how to change font size and line width. Rather, changing the physical size of the plots is much easier to make them suitable to be included in a PDF document. Because the main text would be 10 to 12pt, the letterings in the figure should be 9pt or 10pt. The default line width would be probably fine if the figure is 100 × 80 mm . . . ]

using CairoMakie

mm2pt = let mm2in = 1/25.4, in2pt = 72
  mm2in * in2pt
@show mm2pt

(wid_mm,hei_mm) = (100.0,80.0) # millimeter
(wid_pt, hei_pt) = (wid_mm, hei_mm) .* mm2pt
figsize = (wid_pt, hei_pt)
@show figsize

fig = Figure(size = figsize)
ax = Axis(fig[1,1])
save("tmp.pdf", fig, size=figsize)

Have you already had a look at this page? Figures · Makie

Look for pt_per_unit there and why it’s 0.75 by default

1 Like

No! How do you find it? What keyword do you use to arrive at the page?

I feel really stupid with Makie. Somehow I’m unable to locate relevant documents!!!

I of course went to and looked at various pages. I of course searched google. I of course searched this forum. I think I’m normally very good at finding relevant technical information . . .

1 Like

The page is relatively new so might not be indexed yet. I didn’t find it, I wrote it :smile:

Static page search is relatively dumb so if you don’t look for the right keywords it’s easier to miss stuff than with google


Btw one tip for Makie, I often use GitHub’s code search to search the repository. It often finds the docs faster than through website. It’ll also find issues and such which can be helpful.

1 Like

Sorry I still fail to understand.

I carefully read and re-read the explanation of pt_per_unit and I thought I understood this part:

A Figure with size = (600, 450) will be 600 x 450 points in size when exported with pt_per_unit = 1 , 300 x 225 with pt_per_unit = 0.5 and 1200 x 900 with pt_per_unit = 2 .

So, a figure with size = (300,255) with pt_per_unit = 1 will produce a page 300 × 450 pt.

But the following code still produces a page of 800 × 600 pt . . .

using CairoMakie
figsize = (300,255)
fig = Figure(fontsize=9, size=figsize, pt_per_unit = 1)
ax = Axis(fig[1,1])
save("tmp.pdf", fig, size=figsize, pt_per_unit = 1)

By the way, I don’t know where to put pt_per_unit and size.

I often use GitHub’s code search to search the repository.

I tried that feature sometime ago, but the search seemed to search for filenames. Your words seem to indicate that you can search the contents of the files.

[I’ve deleted my original comment. Sorry!]

If I search for figure size, the first result seems to be the docs Julius linked:

1 Like

Are you on 0.20? You getting a 800x600 figure indicates that the new size keyword is ignored and the default is still the old one, so you’re probably on 0.19

OMG! It seems my Julia installation was corrupted, perhaps similarly to

I just didn’t realize that CairoMakie remained “updatable” even after I updated all packages.

Since the method suggested in the Stackoverflow thread I quote above didn’t work for me, I just deleted everything under ~/.julia and stated over.

This time I got the latest version of CarioMakie as shown below and I was of course able to scale the figure as described in your document.

Phew! Thanks!

(@v1.9) pkg> status
Status `~/.julia/environments/v1.9/Project.toml`
  [13f3f980] CairoMakie v0.11.1

@jules Are you the second author of this paper, ? In the manuscript I’m writing now, I plan to mention you in the “acknowledgements” section for answering so many (often stupid) questions from me, as well as citing the paper. (I tried to find a way to private-message you but didn’t find it.)

1 Like

Yes that would be me, now you know why I’m answering questions all the time :wink:

1 Like

By the way, my assessment

was totally wrong. I’m now on a different Mac machine and had exactly the same problem.

I then learned why a package which “may be upgradable” (as reported by Pkg.status) is not upgraded unless you force it by specifying the desired version number.

In my particular case, CairoMakie and NCDatasets weren’t upgraded. When I forced them to be their latest versions, a lot of other packages were downgraded. But, after removing Rasters, all potentially “upgradable” packages were upgraded. So, it seems (although I’m not 100% sure) that that was because Rasters depends on older versions of some packages on which Makie depends.