Merge pull request #2286 from daschw/colorgradient
Update for new PlotThemes release
This commit is contained in:
commit
7e54cd4306
@ -1,7 +1,7 @@
|
|||||||
name = "Plots"
|
name = "Plots"
|
||||||
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||||
author = ["Tom Breloff (@tbreloff)"]
|
author = ["Tom Breloff (@tbreloff)"]
|
||||||
version = "0.28.0"
|
version = "0.28.1"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
|
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
|
||||||
@ -39,7 +39,7 @@ GeometryTypes = "0.7"
|
|||||||
JSON = "0.21"
|
JSON = "0.21"
|
||||||
Measures = "0.3"
|
Measures = "0.3"
|
||||||
NaNMath = "0.3"
|
NaNMath = "0.3"
|
||||||
PlotThemes = "0.2, 0.4"
|
PlotThemes = "0.2, 1"
|
||||||
PlotUtils = "0.6.1"
|
PlotUtils = "0.6.1"
|
||||||
RecipesBase = "0.6, 0.7"
|
RecipesBase = "0.6, 0.7"
|
||||||
Reexport = "0.2"
|
Reexport = "0.2"
|
||||||
|
|||||||
1652
src/precompile.jl
1652
src/precompile.jl
File diff suppressed because it is too large
Load Diff
@ -4,39 +4,20 @@
|
|||||||
Specify the colour theme for plots.
|
Specify the colour theme for plots.
|
||||||
"""
|
"""
|
||||||
function theme(s::Symbol; kw...)
|
function theme(s::Symbol; kw...)
|
||||||
defaults = _get_defaults(s)
|
defaults = PlotThemes._themes[s].defaults
|
||||||
_theme(s, defaults; kw...)
|
_theme(s, defaults; kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _get_defaults(s::Symbol)
|
|
||||||
thm = PlotThemes._themes[s]
|
|
||||||
if :defaults in fieldnames(typeof(thm))
|
|
||||||
return thm.defaults
|
|
||||||
else # old PlotTheme type
|
|
||||||
defaults = KW(
|
|
||||||
:bg => thm.bg_secondary,
|
|
||||||
:bginside => thm.bg_primary,
|
|
||||||
:fg => thm.lines,
|
|
||||||
:fgtext => thm.text,
|
|
||||||
:fgguide => thm.text,
|
|
||||||
:fglegend => thm.text,
|
|
||||||
:palette => thm.palette,
|
|
||||||
)
|
|
||||||
if thm.gradient !== nothing
|
|
||||||
push!(defaults, :gradient => thm.gradient)
|
|
||||||
end
|
|
||||||
return defaults
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function _theme(s::Symbol, defaults::KW; kw...)
|
function _theme(s::Symbol, defaults::KW; kw...)
|
||||||
# Reset to defaults to overwrite active theme
|
# Reset to defaults to overwrite active theme
|
||||||
reset_defaults()
|
reset_defaults()
|
||||||
|
|
||||||
# Set the theme's gradient as default
|
# Set the theme's gradient as default
|
||||||
if haskey(defaults, :gradient)
|
fix_colorgradient!(defaults)
|
||||||
|
if haskey(defaults, :colorgradient)
|
||||||
PlotUtils.clibrary(:misc)
|
PlotUtils.clibrary(:misc)
|
||||||
PlotUtils.default_cgrad(default = :sequential, sequential = PlotThemes.gradient_name(s))
|
PlotUtils.default_cgrad(default = :sequential, sequential = PlotThemes.gradient_name(s))
|
||||||
|
pop!(defaults, :colorgradient)
|
||||||
else
|
else
|
||||||
PlotUtils.clibrary(:Plots)
|
PlotUtils.clibrary(:Plots)
|
||||||
PlotUtils.default_cgrad(default = :sequential, sequential = :inferno)
|
PlotUtils.default_cgrad(default = :sequential, sequential = :inferno)
|
||||||
@ -44,8 +25,8 @@ function _theme(s::Symbol, defaults::KW; kw...)
|
|||||||
|
|
||||||
# maybe overwrite the theme's gradient
|
# maybe overwrite the theme's gradient
|
||||||
kw = KW(kw)
|
kw = KW(kw)
|
||||||
if haskey(kw, :gradient)
|
if haskey(kw, :colorgradient)
|
||||||
kwgrad = pop!(kw, :gradient)
|
kwgrad = pop!(kw, :colorgradient)
|
||||||
for clib in clibraries()
|
for clib in clibraries()
|
||||||
if kwgrad in cgradients(clib)
|
if kwgrad in cgradients(clib)
|
||||||
PlotUtils.clibrary(clib)
|
PlotUtils.clibrary(clib)
|
||||||
@ -60,6 +41,13 @@ function _theme(s::Symbol, defaults::KW; kw...)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# be compatible with old PlotThemes specifying the colorgradient with `:gradient`
|
||||||
|
function fix_colorgradient!(defaults)
|
||||||
|
if haskey(defaults, :gradient) && !haskey(defaults, :colorgradient)
|
||||||
|
defaults[:colorgradient] = pop!(defaults, :gradient)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@deprecate set_theme(s) theme(s)
|
@deprecate set_theme(s) theme(s)
|
||||||
|
|
||||||
@userplot ShowTheme
|
@userplot ShowTheme
|
||||||
@ -74,11 +62,12 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
|
|||||||
|
|
||||||
@recipe function showtheme(st::ShowTheme)
|
@recipe function showtheme(st::ShowTheme)
|
||||||
thm, cfunc = _get_showtheme_args(st.args...)
|
thm, cfunc = _get_showtheme_args(st.args...)
|
||||||
defaults = _get_defaults(thm)
|
defaults = PlotThemes._themes[thm].defaults
|
||||||
|
|
||||||
# get the gradient
|
# get the gradient
|
||||||
gradient_colors = get(defaults, :gradient, cgrad(:inferno).colors)
|
fix_colorgradient!(defaults)
|
||||||
gradient = cgrad(cfunc.(RGB.(gradient_colors)))
|
gradient_colors = get(defaults, :colorgradient, cgrad(:inferno).colors)
|
||||||
|
colorgradient = cgrad(cfunc.(RGB.(gradient_colors)))
|
||||||
|
|
||||||
# get the palette
|
# get the palette
|
||||||
palette = get(defaults, :palette, get_color_palette(:auto, plot_color(:white), 17))
|
palette = get(defaults, :palette, get_color_palette(:auto, plot_color(:white), 17))
|
||||||
@ -86,7 +75,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
|
|||||||
|
|
||||||
# apply the theme
|
# apply the theme
|
||||||
for k in keys(defaults)
|
for k in keys(defaults)
|
||||||
k in (:gradient, :palette) && continue
|
k in (:colorgradient, :palette) && continue
|
||||||
def = defaults[k]
|
def = defaults[k]
|
||||||
arg = get(_keyAliases, k, k)
|
arg = get(_keyAliases, k, k)
|
||||||
plotattributes[arg] = if typeof(def) <: Colorant
|
plotattributes[arg] = if typeof(def) <: Colorant
|
||||||
@ -139,7 +128,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
|
|||||||
@series begin
|
@series begin
|
||||||
subplot := 4
|
subplot := 4
|
||||||
seriestype := :heatmap
|
seriestype := :heatmap
|
||||||
seriescolor := gradient
|
seriescolor := colorgradient
|
||||||
ticks := -5:5:5
|
ticks := -5:5:5
|
||||||
x, y, z
|
x, y, z
|
||||||
end
|
end
|
||||||
@ -147,7 +136,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
|
|||||||
@series begin
|
@series begin
|
||||||
subplot := 5
|
subplot := 5
|
||||||
seriestype := :surface
|
seriestype := :surface
|
||||||
seriescolor := gradient
|
seriescolor := colorgradient
|
||||||
x, y, z
|
x, y, z
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -159,7 +148,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
|
|||||||
|
|
||||||
@series begin
|
@series begin
|
||||||
subplot := 6
|
subplot := 6
|
||||||
seriescolor := gradient
|
seriescolor := colorgradient
|
||||||
linewidth := 3
|
linewidth := 3
|
||||||
line_z := z
|
line_z := z
|
||||||
x, y, z
|
x, y, z
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user