# Clarifying the behavior of \`PLOTS\_DEFAULTS\` in Plots.jl

**URL:** <https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110>\
**Category:** General Usage\
**Tags:** question, plotting, plots\
**Created:** [May 18, 2025, 1:58am UTC](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110 "2025-05-18T01:58:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shg/32/207943_2.png) [@shg](https://discourse.julialang.org/u/shg)\
**Post date:** [May 18, 2025, 1:58am UTC](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110/1 "2025-05-18T01:58:08Z")

</div>

I’d like to set some default parameters for plotting using Plots.jl by defining the `PLOTS_DEFAULTS` variable in my “startup.jl” . I have questions regarding its behavior:

1. It appears that setting `PLOTS_DEFAULTS` successfully applies my default parameters, and subsequent calls to the `plot()` function respect these settings. However, if I execute the `default()` function, all parameters revert to Plots.jl’s built-in defaults, and my custom `PLOTS_DEFAULTS` settings are lost. Is this the intended behavior? I expected that defining `PLOTS_DEFAULTS` would change the “defaults” themselves, but it seems that the `default()` function does not consider `PLOTS_DEFAULTS`.

2. Given the behavior described above, how can I have my custom parameters defined in `PLOTS_DEFAULTS` re-effective after executing the `default()` function?

3. I want to specify margins (such as `top_margin`) through `PLOTS_DEFAULTS` . Is it possible to set, for example, a `5mm` top margin when `mm` is not available? I don’t want to load a package in my startup.jl just for this.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [May 18, 2025, 7:00am UTC](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110/2 "2025-05-18T07:00:03Z")

</div>

> [@shg](#):
>
> Is this the intended behavior?

It’s not documented so I suppose it’s free to change, but the first line of the 0-positional argument method does suggest it resets the defaults if `reset=true` and there are no other keyword arguments for setting default values:

```julia
function default(; reset = true, kw...)
    (reset && isempty(kw)) && reset_defaults()
    kw = KW(kw)
    Plots.preprocess_attributes!(kw)
    for (k, v) in kw
        default(k, v) # 2-positional method sets 1 default value for 1 key
    end
end

```

Honestly not sure why it’s designed like that because:

1. typical usage with keyword arguments would not reset, so I’d expect zero arguments to not reset either (a no-op overall)
2. I might want to the one call to reset the defaults before I set new values.

---

<div class="post-metadata">

**Author:** ![shg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shg/32/207943_2.png) [@shg](https://discourse.julialang.org/u/shg)\
**Post date:** [May 19, 2025, 2:44pm UTC](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110/3 "2025-05-19T14:44:40Z")

</div>

Thank you @Benny

I usually do something like the following at the beginning of my code:

```julia
default()
default(thickness_scaling = 1.8, legend = false)
default(guidefontsize = 10, titlefontsize = 11, tickfontsize = 8)
default(markersize = 5, linewidth = 2)
default(left_margin = -5mm, bottom_margin = -3mm, right_margin = 0mm, top_margin = 0mm)

```

Here I call `default()` with empty argument first to reset to the defaults and then with custom parameters. Because I mostly always do this, I’d like to have these custom parameters in PLOTS\_DEFAULTS variable so that I should be able to do just the following instead:

```julia
default()

```

to have the same effect. But unfortunately it does not reset to PLOTS\_DEFAULTS but to the “default defaults”. So I wonder whether this is expected or not.

I quickly checked the code and found that neither `default` function nor `reset_defaults` function called from within `default` seems to check `PLOTS_DEFAULTS` at all. Maybe it seems it is designed so. Personally I think `default()` should respect `PLOTS_DEFAULTS`. If not the name `PLOTS_DEFAULTS` does not feel appropriate.

As for my question 3, using `(5, :mm)` instead of `5mm` worked. I am not sure whether this is documented anywhere.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [May 19, 2025, 7:50pm UTC](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110/4 "2025-05-19T19:50:37Z")

</div>

> [@shg](#):
>
> I quickly checked the code and found that neither `default` function nor `reset_defaults` function called from within `default` seems to check `PLOTS_DEFAULTS` at all. Maybe it seems it is designed so.

I’m not the last word on it, but when I checked the source code it seemed that way to me too. The defaults are actually split into several sections so I’m not positive, but it seems hard-coded instead of checking PLOTS\_DEFAULTS. PLOTS\_DEFAULTS only seems to be relevant to an ` __init__ ` step. I think it might have been intentional to have a reset go to the hard-coded values as a reference instead of PLOTS\_DEFAULTS, but I’m just speculating there.

> [@shg](#):
>
> ```julia
> default()
> default(thickness_scaling = 1.8, legend = false)
> default(guidefontsize = 10, titlefontsize = 11, tickfontsize = 8)
> default(markersize = 5, linewidth = 2)
> default(left_margin = -5mm, bottom_margin = -3mm, right_margin = 0mm, top_margin = 0mm)
> 
> ```

Could you get away with making a variant default function `mydefault()` that does all this instead of using PLOTS\_DEFAULTS? If there isn’t a package for you to put it in, you could just `include` the one method into every plotting script and call it every time you need a personalized reset.

---

<div class="post-metadata">

**Author:** ![shg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shg/32/207943_2.png) [@shg](https://discourse.julialang.org/u/shg)\
**Post date:** [May 21, 2025, 3:06am UTC](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110/5 "2025-05-21T03:06:39Z")

</div>

Thanks for the suggestion. I will define a function for applying custom paramters to a set of attributes. It’s easy and solves what I want to do for now. I think it will be useful if Plots.jl’s `default` provides more flexbile style switching.
