From ef5cba5229ed54dfe9872e8d934470354721c864 Mon Sep 17 00:00:00 2001 From: Stuart Daines Date: Mon, 2 May 2022 20:31:36 +0100 Subject: [PATCH] Document PlotRecipes, fix ordering of stepped line plots, update to v0.14.3 --- Project.toml | 2 +- docs/src/PALEOmodel.md | 9 +++++++-- src/PALEOmodel.jl | 4 ---- src/PlotRecipes.jl | 36 +++++++++++++++++------------------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Project.toml b/Project.toml index 1d2fc4f..b4f33a9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PALEOmodel" uuid = "bf7b4fbe-ccb1-42c5-83c2-e6e9378b660c" authors = ["Stuart Daines "] -version = "0.14.2" +version = "0.14.3" [deps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" diff --git a/docs/src/PALEOmodel.md b/docs/src/PALEOmodel.md index 18b421e..5a39825 100644 --- a/docs/src/PALEOmodel.md +++ b/docs/src/PALEOmodel.md @@ -115,14 +115,19 @@ add_record! ## Plot output -Plot recipes for `PALEOboxes.FieldArray` TODO - ```@meta CurrentModule = PALEOmodel ``` ```@docs +RecipesBase.apply_recipe(::Dict{Symbol, Any}, fa::FieldArray) +RecipesBase.apply_recipe(::Dict{Symbol, Any}, output::AbstractOutputWriter, vars::Union{AbstractString, Vector{<:AbstractString}}, selectargs::NamedTuple) +RecipesBase.apply_recipe(::Dict{Symbol, Any}, outputs::Vector{<:AbstractOutputWriter}, vars::Union{AbstractString, Vector{<:AbstractString}}, selectargs::NamedTuple) +RecipesBase.apply_recipe(::Dict{Symbol, Any}, fr::FieldRecord, selectargs::NamedTuple) +RecipesBase.apply_recipe(::Dict{Symbol, Any}, fas::Vector{<:FieldArray}) + PlotPager Plot.test_heatmap_edges + ``` ## Analyze reaction network ```@meta diff --git a/src/PALEOmodel.jl b/src/PALEOmodel.jl index 6c13bc4..290925a 100644 --- a/src/PALEOmodel.jl +++ b/src/PALEOmodel.jl @@ -10,10 +10,6 @@ import SparsityTracing PB.value_ad(x::SparsityTracing.ADval) = SparsityTracing.value(x) PB.value_ad(x::ForwardDiff.Dual) = ForwardDiff.value(x) -"base type for plot commands" -abstract type AbstractPlot -end - "base type for OutputWriters" abstract type AbstractOutputWriter end diff --git a/src/PlotRecipes.jl b/src/PlotRecipes.jl index cc51e49..e253593 100644 --- a/src/PlotRecipes.jl +++ b/src/PlotRecipes.jl @@ -25,7 +25,7 @@ Optional `kwargs` provides keyword arguments supplied to `plot` julia> pp(:newpage) # flush any partial screen and start new page (NB: always add this at end of a sequence!) # Commands -- `pp(p::AbstractPlot)`: accumulate plot p +- `pp(p)`: accumulate plot p - `pp(:skip)`: leave a blank panel - `pp(:newpage)`: fill with blank panels and start new page - `pp(p1, p2, ...)`: multiple plots/commands in one call @@ -115,11 +115,9 @@ end ############################### """ - @recipe function f(output::AbstractOutputWriter, vars::Union{AbstractString, Vector}, selectargs::NamedTuple=NamedTuple()) + plot(output::AbstractOutputWriter, vars::Union{AbstractString, Vector{<:AbstractString}}, selectargs::NamedTuple=NamedTuple()) -Plot recipe that calls `PB.get_field(output, var)` - -and passes on to `@recipe function f(fr::FieldRecord, selectargs::NamedTuple)` +Plot recipe that calls `PB.get_field(output, var)`, and passes on to `plot(fr::FieldRecord, selectargs)` Additional features: - if `vars` is a Vector, create a plot series for each element. @@ -152,10 +150,10 @@ RecipesBase.@recipe function f( end """ - @recipe function f(outputs::Vector{<:AbstractOutputWriter}, vars::Union{AbstractString, Vector}, selectargs::NamedTuple=NamedTuple()) + plot(outputs::Vector{<:AbstractOutputWriter}, vars::Union{AbstractString, Vector{<:AbstractString}}, selectargs::NamedTuple=NamedTuple()) -Pass through (ie "broadcast") each element of `output` to -`@recipe function f(output::AbstractOutputWriter, vars::Union{AbstractString, Vector}, selectargs::NamedTuple=NamedTuple())`, +Pass through (ie "broadcast") each element `output` of `outputs` to +`plot(output::AbstractOutputWriter, vars, selectargs)`, adding a `labelprefix` (index in `outputs` Vector) to identify each plot series produced. """ RecipesBase.@recipe function f( @@ -175,9 +173,9 @@ end """ - @recipe function f(fr::FieldRecord, selectargs::NamedTuple) + plot(fr::FieldRecord, selectargs::NamedTuple) -Plot recipe that calls `get_array(fr; selectargs...)` and passes on to `@recipe function f(fa::FieldArray)`. +Plot recipe that calls `get_array(fr; selectargs...)` and passes on to `plot(fa::FieldArray)`. Vector-valued fields in `selectargs` are broadcasted (generating a separate plot series for each combination) """ @@ -195,7 +193,7 @@ end """ - @recipe function f(fa::FieldArray; kwargs...) + plot(fa::FieldArray; kwargs...) Plot recipe that plots `fa`. If `fa` has a single dimension, this is suitable for a line-like plot, if two dimensions, a heatmap. @@ -350,9 +348,9 @@ RecipesBase.@recipe function f( end """ - @recipe function f(fas::Vector{<:FieldArray}; labelprefix="") + plot(fas::Vector{<:FieldArray}; labelprefix="") -Pass through (ie "broadcast") each element of `fas` to `@recipe function f(fa::FieldArray)`, +Pass through (ie "broadcast") each element of `fas` to `plot(fa::FieldArray)`, generating one plot series for each. Adds Vector index to `labelprefix`. """ RecipesBase.@recipe function f( @@ -378,17 +376,17 @@ function create_stepped(z1, z2, data) z = Float64[] d = Float64[] - if z1[end] < z1[begin] - zlower, zupper = z1, z2 + if (z1[end] > z1[begin]) == (z2[begin] > z1[begin]) + zfirst, zsecond = z1, z2 else - zlower, zupper = z2, z1 + zfirst, zsecond = z2, z1 end - for (dval, zl, zu) in zip(data, zlower, zupper) - push!(z, zu) - push!(d, dval) + for (dval, zl, zu) in zip(data, zfirst, zsecond) push!(z, zl) push!(d, dval) + push!(z, zu) + push!(d, dval) end return z, d end