Changing default parameters

How can I change the default parameters of a function?

I have this code:

using Plots

x=0:0.01:100
y1=sin.(x)

p = plot(x,y1, width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12, legend=false)

I want to be able to write:

using Plots
include("my_defaults.jl")

x=0:0.01:100
y1=sin.(x)

p=plot(x,y1)

and achieve the same result. Can I redefine the function plot to use different default parameters?

You can use the default function available with Plots.jl:

https://docs.juliaplots.org/latest/api/#Plots.default

Just put your preferred settings in this function, and it will set them as the defaults for your session:

default(width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12)

2 Likes