Yly
Yly

Reputation: 2330

How to set the default color gradient in Plots.jl

In Julia's Plots package, I can change the color of a surface plot like this:

plot(mySurface,st=:surface,c=:blues)

How can I change the default color gradient so that I don't have to put the c=:blues every time?

(The relevant Plots doc page does not state how to modify the default.)

Upvotes: 3

Views: 1419

Answers (3)

hckr
hckr

Reputation: 5583

See the tip from the Julia Plots documentation:

Tip: You can see the default value for a given argument with default(arg::Symbol), and set the default value with default(arg::Symbol, value) or default(; kw...). For example set the default window size and whether we should show a legend with default(size=(600,400), leg=false).

http://docs.juliaplots.org/latest/basics/

Hence, you can set the default you want with

default(c=:blues)

Though you probably want to set a new default for fillcolor rather than seriescolor or its alias c since seriescolor will also affect color of other type of plots and you probably would not want that.

default(fillcolor=:blues)

The default will work so long as you do not set any other default or restart your Julia session.

If you want your new default to work even after restarting Julia you might want to try Requires.jl and your startup file (~/.julia/config/startup.jl) with something like the following,

using Requires
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" Plots.default(fillcolor=:blues)

where 91a5bcdd-55d7-5caf-9e0b-520d859cae80 is the UUID of Plots.jl package in the registry.

Upvotes: 2

Pei Huang
Pei Huang

Reputation: 344

I saw a possible solution here. https://github.com/JuliaPlots/Plots.jl/issues/87

with(c = :blue) do
plot!(rand(5))
plot!(rand(5))
end

Upvotes: 2

Felipe Lema
Felipe Lema

Reputation: 2718

You should either the palette or the m keyword as shown in the examples:

y = rand(100)
plot(0:10:100, rand(11, 4), lab="lines", w=3, palette=:grays, fill=0, α=0.6)
scatter!(y, zcolor=abs.(y .- 0.5), m=(:heat, 0.8, Plots.stroke(1, :green)), ms=10 * abs.(y .- 0.5) .+ 4, lab="grad")

Upvotes: 0

Related Questions