In Julia
plotting with Plots
, I know how to set the various attributes when using plot()
(Attributes).
I want to know how to set the default attributes, so that I don't need to set them every time.
For instance, I want to change the font-family to another one, or show the minor ticks always.
I googled but I can not find the way.
This is the way:
Use the default()
function like so
using Plots
default(titlefont = (20, "times"), legendfontsize = 18, guidefont = (18, :darkgreen), tickfont = (12, :orange), guide = "x", framestyle = :zerolines, yminorgrid = true)
plot([sin, cos], -2π, 2π, label = ["sin(θ)" "cos(θ)"], title = "Trigonometric Functions", xlabel = "θ", linewidth = 2, legend = :outertopleft)
Taken from the documentation here. I know the Plots.jl docs can be a bit tricky to navigate due to their size, but in this case I just typed default
into the doc search box.
Note that when using the default
function you don't supply the keyword args in subsequent calls to plot
, unless of course you want to change away from your newly specified defaults.
Since you are asking for a way to save defaults across sessions, I will also point you to this additional tip from the installation docs:
You can override standard default values in your
~/.julia/config/startup.jl
file:PLOTS_DEFAULTS = Dict(:markersize => 10, :legend => false, warn_on_unsupported = false)
So here you are defining the new defaults as a dictionary which is used as an environment variable, which allows setting defaults before loading Plots (and thus without having the default
function available).