How can I set the default font in Makie?

Main question

Hi, I am new to Makie.jl for publication-quality vector graphics. I had tried below tutorial but I don’t get how set_theme! function works.

For example, I understand that there is no optional argument font or fontfamily to change all fonts of a whole plot, but we could change one by one. In next plot, I changed the font of title to ‘computer modern’.

using CairoMakie

f = Figure()
ax = Axis(f[1,1], titlefont = "titlefont changed", title = "Computer Modern", xlabel = "Default font")
scatter!(ax, rand(100), rand(100))
save("f.png", f)

This is not perfect and I need global or default setting. Next trial:

set_theme!(titlefont = "Computer Modern")
g = Figure()
bx = Axis(g[1,1], title = "titlefont NOT changed", xlabel = "Default font")
scatter!(bx, rand(100), rand(100))
save("g.png", g)

Of course set_theme!(Theme(titlefont = "Computer Modern")) doesn’t work. What I missed?


And if you don’t mind, could you answer short questions, please?

  • (a) f = Figure(); ax = Axis(f[1,1]) things are essential? To write title or x,y-labels?
  • (b) Why axislegend is not axislegend!? So confused.
  • (c) Is there any additional documentation consists of what plotting functions return? For example, I know what lines or hist do, but don’t know what they return.

Any answer would be great. Thank you.


  • julia 1.8.5
  • CairoMakie v0.10.2
  • windows 11

Let me point you to a different section of the docs that explains this:

You can pass figure and axis special keywords directly to non-mutating plotting functions:

Lots of functions in Makie don’t have ! because it’s implicit that all plotting functions mutate something. It’s just that for the primitive plotting functions, we want to differentiate whether they create their own figure/axis (lines) or need to mutate an existing one (lines!).

As I mentioned in first question, I had could change a font of one plot by manual way but I want to know how I change global setting. Your reference doesn’t seems to be a sort of mine. And, actually, I had read that first(so I found set_theme!) but I couldn’t understand almost of them, that doesn’t work or couldn’t applied to my job, for example:

f = Figure(fontsize = 60, fonts = (; regular = "Arial", weird = "Arial"))
Axis(f[1, 1], title = "A title", xlabel = "An x label", xlabelfont = :weird)
save("f.png", f)

Yes, fontsize is perfectly works, but fonts = (; regular = "Arial", weird = "Arial") can’t affect to result. What I have to change? What is :weird? fonts and font, which is right? Even I success to modify this, I’ll never deal with default setting. Sure, I guess it’s because today is my first day with Makie but I feel very hard and complicated.

Thanks, your answers surely help me!!!

But again, I don’t get what fig, ax, p exacatly are in fig, ax, p = lines(cumsum(randn(1000)) ~~) although this destructive way was introduced in other many examples. I tried some tutorials and learn intuitively what they do some roles, however,

  • I don’t know that all plotting functions return exactly same 3-tuple result or not.
  • I guess first one fig is just plot itself, like GR backend, OK.
  • I guess second one ax is for… or return of Axis? to manipulate in further? But I think Axis is a struct, not function. This kind of thing make me confused.
  • I have no idea of third one p.

EXACTLY. I know you can’t explain them all, so I hope more detailed documentation, but if not exists, I would learn by do maybe. Again, thank you.

If you do lines(...) then a Figure is created (container of all other content with a layout), then an Axis inside that (the object with axis scales, title, labels, etc, a container for plots) and inside that Axis a Lines plot primitive is created. These are returned as one FigureAxisPlot object which can be destructured, not unlike tuples, into its three components via fig, ax, lin = ... or whatever you want to call the variables.

If you run lines!(...) then Figure and Axis must exist already, so only a Lines plot object needs to be returned.

You can set the same font options either in the global theme or directly for one specific Figure. The :weird font type just demonstrates that you can come up with your own categories, you don’t have to use only the predefined :regular, :bold, :bold_italic, :italic

set_theme!(fonts = (; regular = "Comic Sans", bold = "Times New Roman Bold"))
lines(0..10, sin; axis = (; title = "A title"))

Thanks for all your helps. I feel I got something!