From a59e8411c9006087242d9d60c092c8d029c8fb53 Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Thu, 30 Apr 2020 22:30:03 -1000 Subject: [PATCH 1/5] update clims arg description --- src/arg_desc.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index ef2aea6c..cf86e7f1 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -104,7 +104,7 @@ const _arg_desc = KW( :legendtitlefontrotation => "Real. Font rotation of the legend title", :legendtitlefontcolor => "Color Type. Font color of the legend title", :colorbar => "Bool (show the colorbar?) or Symbol (colorbar position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:legend` (matches legend value) (note: only some may be supported in each backend)", -:clims => "`:auto` or NTuple{2,Number}. Fixes the limits of the colorbar.", +:clims => "`:auto`, NTuple{2,Number}, or a function that takes series data in and returns NTuple{2,Number}. Fixes the limits of the colorbar.", :legendfont => "Font. Font of legend items.", :legendtitlefont => "Font. Font of the legend title.", :annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String or PlotText (created with `text(args...)`) Add one-off text annotations at the x,y coordinates.", From 294ade8aad1163ef9ebe92507f73bc7468bf3c4d Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Thu, 30 Apr 2020 23:32:30 -1000 Subject: [PATCH 2/5] refactor get_clims calls to use operators --- src/utils.jl | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 280c6387..069eda07 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -410,44 +410,46 @@ xlims(sp_idx::Int = 1) = xlims(current(), sp_idx) ylims(sp_idx::Int = 1) = ylims(current(), sp_idx) zlims(sp_idx::Int = 1) = zlims(current(), sp_idx) +# These functions return an operator for use in `get_clims(::Seres, op)` +process_clims(lims::NTuple{2}) = z -> _update_clims(z..., lims...) ∘ ignorenan_extrema +process_clims(s::Union{Symbol, Nothing, Missing}) = ignorenan_extrema +# don't specialize on ::Function otherwise python functions won't work +process_clims(f) = f -function get_clims(sp::Subplot) +function get_clims(sp::Subplot, op = process_clims(sp[:clims])) zmin, zmax = Inf, -Inf for series in series_list(sp) if series[:colorbar_entry] - zmin, zmax = _update_clims(zmin, zmax, get_clims(series)...) + zmin, zmax = _update_clims(zmin, zmax, get_clims(series, op)...) end end - clims = sp[:clims] - if is_2tuple(clims) - isfinite(clims[1]) && (zmin = clims[1]) - isfinite(clims[2]) && (zmax = clims[2]) - end return zmin <= zmax ? (zmin, zmax) : (NaN, NaN) end -function get_clims(sp::Subplot, series::Series) +function get_clims(sp::Subplot, series::Series, op = process_clims(sp[:clims])) zmin, zmax = if series[:colorbar_entry] - get_clims(sp) + get_clims(sp, op) else - get_clims(series) - end - clims = sp[:clims] - if is_2tuple(clims) - isfinite(clims[1]) && (zmin = clims[1]) - isfinite(clims[2]) && (zmax = clims[2]) + get_clims(series, op) end return zmin <= zmax ? (zmin, zmax) : (NaN, NaN) end -function get_clims(series::Series) +""" + get_clims(::Series, op=Plots.ignorana_extrema) + +Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`, +which must be written to return the tuple `(zmin, zmax)`. The default op is the extrema of the finite +values of the input. +""" +function get_clims(series::Series, op=ignorenan_extrema) zmin, zmax = Inf, -Inf z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface) for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z]) if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Union{Missing, Real}) - zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals.surf)...) + zmin, zmax = _update_clims(zmin, zmax, op(vals.surf)...) elseif (vals !== nothing) && (eltype(vals) <: Union{Missing, Real}) - zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals)...) + zmin, zmax = _update_clims(zmin, zmax, op(vals)...) end end return zmin <= zmax ? (zmin, zmax) : (NaN, NaN) From 8cce78c890911a64b1877be02a6952106c868842 Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Thu, 30 Apr 2020 23:38:52 -1000 Subject: [PATCH 3/5] fix typos --- src/utils.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 069eda07..e3356f77 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -416,7 +416,7 @@ process_clims(s::Union{Symbol, Nothing, Missing}) = ignorenan_extrema # don't specialize on ::Function otherwise python functions won't work process_clims(f) = f -function get_clims(sp::Subplot, op = process_clims(sp[:clims])) +function get_clims(sp::Subplot, op=process_clims(sp[:clims])) zmin, zmax = Inf, -Inf for series in series_list(sp) if series[:colorbar_entry] @@ -426,7 +426,7 @@ function get_clims(sp::Subplot, op = process_clims(sp[:clims])) return zmin <= zmax ? (zmin, zmax) : (NaN, NaN) end -function get_clims(sp::Subplot, series::Series, op = process_clims(sp[:clims])) +function get_clims(sp::Subplot, series::Series, op=process_clims(sp[:clims])) zmin, zmax = if series[:colorbar_entry] get_clims(sp, op) else @@ -436,13 +436,14 @@ function get_clims(sp::Subplot, series::Series, op = process_clims(sp[:clims])) end """ - get_clims(::Series, op=Plots.ignorana_extrema) + get_clims(::Series, op=Plots.ignoranan_extrema) Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`, which must be written to return the tuple `(zmin, zmax)`. The default op is the extrema of the finite values of the input. """ function get_clims(series::Series, op=ignorenan_extrema) + @show op zmin, zmax = Inf, -Inf z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface) for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z]) From 10a5c2ed1dc56944fe41f15a488a34390b394ee4 Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Fri, 1 May 2020 00:10:27 -1000 Subject: [PATCH 4/5] fix bug with Tuple clims and fix typos --- src/utils.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index e3356f77..f9e6dbed 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -411,8 +411,8 @@ ylims(sp_idx::Int = 1) = ylims(current(), sp_idx) zlims(sp_idx::Int = 1) = zlims(current(), sp_idx) # These functions return an operator for use in `get_clims(::Seres, op)` -process_clims(lims::NTuple{2}) = z -> _update_clims(z..., lims...) ∘ ignorenan_extrema -process_clims(s::Union{Symbol, Nothing, Missing}) = ignorenan_extrema +process_clims(lims::NTuple{2,<:Number}) = (zlims -> ifelse.(isfinite.(lims), lims, zlims)) ∘ ignorenan_extrema +process_clims(s::Union{Symbol,Nothing,Missing}) = ignorenan_extrema # don't specialize on ::Function otherwise python functions won't work process_clims(f) = f @@ -439,11 +439,10 @@ end get_clims(::Series, op=Plots.ignoranan_extrema) Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`, -which must be written to return the tuple `(zmin, zmax)`. The default op is the extrema of the finite +which must return the tuple `(zmin, zmax)`. The default op is the extrema of the finite values of the input. """ function get_clims(series::Series, op=ignorenan_extrema) - @show op zmin, zmax = Inf, -Inf z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface) for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z]) From 0aa606d8350215963e985633c1517ba6c9b8218a Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Mon, 4 May 2020 11:05:53 -1000 Subject: [PATCH 5/5] fix typo in get_clims function docstring --- src/utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index f9e6dbed..c3dd924d 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -436,7 +436,7 @@ function get_clims(sp::Subplot, series::Series, op=process_clims(sp[:clims])) end """ - get_clims(::Series, op=Plots.ignoranan_extrema) + get_clims(::Series, op=Plots.ignorenan_extrema) Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`, which must return the tuple `(zmin, zmax)`. The default op is the extrema of the finite