Merge pull request #2286 from daschw/colorgradient

Update for new PlotThemes release
This commit is contained in:
Daniel Schwabeneder 2019-11-27 19:42:09 +01:00 committed by GitHub
commit 7e54cd4306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 861 additions and 848 deletions

View File

@ -1,7 +1,7 @@
name = "Plots"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
author = ["Tom Breloff (@tbreloff)"]
version = "0.28.0"
version = "0.28.1"
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@ -39,7 +39,7 @@ GeometryTypes = "0.7"
JSON = "0.21"
Measures = "0.3"
NaNMath = "0.3"
PlotThemes = "0.2, 0.4"
PlotThemes = "0.2, 1"
PlotUtils = "0.6.1"
RecipesBase = "0.6, 0.7"
Reexport = "0.2"

File diff suppressed because it is too large Load Diff

View File

@ -4,39 +4,20 @@
Specify the colour theme for plots.
"""
function theme(s::Symbol; kw...)
defaults = _get_defaults(s)
defaults = PlotThemes._themes[s].defaults
_theme(s, defaults; kw...)
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...)
# Reset to defaults to overwrite active theme
reset_defaults()
# Set the theme's gradient as default
if haskey(defaults, :gradient)
fix_colorgradient!(defaults)
if haskey(defaults, :colorgradient)
PlotUtils.clibrary(:misc)
PlotUtils.default_cgrad(default = :sequential, sequential = PlotThemes.gradient_name(s))
pop!(defaults, :colorgradient)
else
PlotUtils.clibrary(:Plots)
PlotUtils.default_cgrad(default = :sequential, sequential = :inferno)
@ -44,8 +25,8 @@ function _theme(s::Symbol, defaults::KW; kw...)
# maybe overwrite the theme's gradient
kw = KW(kw)
if haskey(kw, :gradient)
kwgrad = pop!(kw, :gradient)
if haskey(kw, :colorgradient)
kwgrad = pop!(kw, :colorgradient)
for clib in clibraries()
if kwgrad in cgradients(clib)
PlotUtils.clibrary(clib)
@ -60,6 +41,13 @@ function _theme(s::Symbol, defaults::KW; kw...)
return
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)
@userplot ShowTheme
@ -74,11 +62,12 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
@recipe function showtheme(st::ShowTheme)
thm, cfunc = _get_showtheme_args(st.args...)
defaults = _get_defaults(thm)
defaults = PlotThemes._themes[thm].defaults
# get the gradient
gradient_colors = get(defaults, :gradient, cgrad(:inferno).colors)
gradient = cgrad(cfunc.(RGB.(gradient_colors)))
fix_colorgradient!(defaults)
gradient_colors = get(defaults, :colorgradient, cgrad(:inferno).colors)
colorgradient = cgrad(cfunc.(RGB.(gradient_colors)))
# get the palette
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
for k in keys(defaults)
k in (:gradient, :palette) && continue
k in (:colorgradient, :palette) && continue
def = defaults[k]
arg = get(_keyAliases, k, k)
plotattributes[arg] = if typeof(def) <: Colorant
@ -139,7 +128,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
@series begin
subplot := 4
seriestype := :heatmap
seriescolor := gradient
seriescolor := colorgradient
ticks := -5:5:5
x, y, z
end
@ -147,7 +136,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
@series begin
subplot := 5
seriestype := :surface
seriescolor := gradient
seriescolor := colorgradient
x, y, z
end
@ -159,7 +148,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
@series begin
subplot := 6
seriescolor := gradient
seriescolor := colorgradient
linewidth := 3
line_z := z
x, y, z