Where is the right place to put default settings for Plots.jl

I would like to set the default plotting style, e.g., default(grid=:off, box=:on), when using Plots.jl to avoid doing it every time when I need to use it.
putting it in startup.jl doesn’t work as an error occurs. So where is the right place?

ERROR: LoadError: UndefVarError: default not defined
Stacktrace:
 [1] top-level scope
   @ C:\Users\xxx\.julia\config\startup.jl:1
in expression starting at C:\Users\xxx\.julia\config\startup.jl:1

I would say at the top of each script. If you want to call default, you need to have Plots loaded. And putting using Plots in your startup is probably not something you want.

You can define a mydefaults constant in startup, and do default(mydefaults...) if you want.

I have in my startup.jl:

const PLOTS_DEFAULTS = Dict(:theme => :wong, :fontfamily => "Computer Modern",
    :label => nothing, :dpi => 600
)
3 Likes

This really solved the problem! thanks!

Then one last question, :legend_background_color=> “ARGB(1.0,1.0,1.0,0.5)” leads to an error, is there an way to get this right?

That seems to require Plots.jl to be loaded at startup.
I would try something more generic like:

:legend_background_color => :transparent

You need to test the exact syntax required and also remove the frame around the legend, I guess. But do not know now how to do partial transparency easily in startup.jl. To think about.

That’s a way :grinning: , although I want half transparency. Thank you!

Try:

const PLOTS_DEFAULTS = Dict(:legend_background_color => “0x88ffffff”)

I am not able to test it right now, but I have used it as a direct parameter to plot.

2 Likes

test passed!

1 Like

It works!

For future reference, we could find the hexadecimal colour code using:

using Colors
hex(ARGB(1.0,1.0,1.0,0.5))
"80FFFFFF"
1 Like