# How can I set the default font in Makie?

**URL:** <https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003>\
**Category:** Visualization\
**Created:** [February 22, 2023, 9:19am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003 "2023-02-22T09:19:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)\
**Post date:** [February 22, 2023, 9:19am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/1 "2023-02-22T09:19:07Z")

</div>

## 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.

[https://docs.makie.org/stable/documentation/theming/index.html#theming](https://docs.makie.org/stable/documentation/theming/index.html#theming)

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’.

```julia-auto
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)

```

 ![f](https://global.discourse-cdn.com/julialang/original/3X/d/1/d1eb356eec3b848bc0f04c0086b3db15268d0e01.png)

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

```julia-auto
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)

```

 ![g](https://global.discourse-cdn.com/julialang/original/3X/9/b/9b21f99d9f283c2df8d2ed0bb2b1165415d36c96.png)

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

## Others

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.

## Environment

- julia 1.8.5
- CairoMakie v0.10.2
- windows 11

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 22, 2023, 9:43am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/2 "2023-02-22T09:43:44Z")

</div>

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

[https://docs.makie.org/stable/documentation/fonts/#symbol](https://docs.makie.org/stable/documentation/fonts/#symbol)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 22, 2023, 9:44am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/3 "2023-02-22T09:44:37Z")

</div>

> [@rmsmsgood](#):
>
> 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.

[https://docs.makie.org/stable/documentation/plot\_method\_signatures/](https://docs.makie.org/stable/documentation/plot_method_signatures/)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 22, 2023, 9:45am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/4 "2023-02-22T09:45:33Z")

</div>

> [@rmsmsgood](#):
>
> (a) `f = Figure(); ax = Axis(f[1,1])` things are essential? To write title or x,y-labels?

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

[https://docs.makie.org/stable/documentation/plot\_method\_signatures/#special\_keyword\_arguments](https://docs.makie.org/stable/documentation/plot_method_signatures/#special_keyword_arguments)

> [@rmsmsgood](#):
>
> (b) Why `axislegend` is not `axislegend!`? So confused.

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!`).

---

<div class="post-metadata">

**Author:** ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)\
**Post date:** [February 22, 2023, 10:17am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/5 "2023-02-22T10:17:24Z")

</div>

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:

```julia
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)

```

 ![f](https://global.discourse-cdn.com/julialang/original/3X/a/f/aff1c71191249dc0d12ebc5086950fd7a524f436.png)

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.

---

<div class="post-metadata">

**Author:** ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)\
**Post date:** [February 22, 2023, 10:18am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/6 "2023-02-22T10:18:27Z")

</div>

> [@jules](#):
>
> > [@rmsmsgood](#):
> >
> > (a) `f = Figure(); ax = Axis(f[1,1])` things are essential? To write title or x,y-labels?
> 
> You can pass `figure` and `axis` special keywords directly to non-mutating plotting functions:
> 
> [https://docs.makie.org/stable/documentation/plot\_method\_signatures/#special\_keyword\_arguments](https://docs.makie.org/stable/documentation/plot_method_signatures/#special_keyword_arguments)
> 
> > [@rmsmsgood](#):
> >
> > (b) Why `axislegend` is not `axislegend!`? So confused.
> 
> 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!`).

Thanks, your answers surely help me!!!

> [@jules](#):
>
> [Page Redirection](https://docs.makie.org/stable/documentation/plot_method_signatures/)

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 22, 2023, 10:47am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/7 "2023-02-22T10:47:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 22, 2023, 10:51am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/8 "2023-02-22T10:51:55Z")

</div>

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`

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

```

 ![Screenshot](https://global.discourse-cdn.com/julialang/original/3X/4/a/4a3ee00444d92e9d7848001f05028e7fd8a5bb4e.png)

---

<div class="post-metadata">

**Author:** ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)\
**Post date:** [February 23, 2023, 1:16am UTC](https://discourse.julialang.org/t/how-can-i-set-the-default-font-in-makie/95003/9 "2023-02-23T01:16:21Z")

</div>

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