add zerror recipe

This commit is contained in:
Daniel Schwabeneder 2020-04-07 16:06:12 +02:00
parent 7abab41f2b
commit 819e91aa37
4 changed files with 50 additions and 35 deletions

View File

@ -267,6 +267,7 @@ const _series_defaults = KW(
:bar_edges => false, :bar_edges => false,
:xerror => nothing, :xerror => nothing,
:yerror => nothing, :yerror => nothing,
:zerror => nothing,
:ribbon => nothing, :ribbon => nothing,
:quiver => nothing, :quiver => nothing,
:arrow => nothing, # allows for adding arrows to line/path... call `arrow(args...)` :arrow => nothing, # allows for adding arrows to line/path... call `arrow(args...)`
@ -593,6 +594,7 @@ add_aliases(:color_palette, :palette)
add_aliases(:overwrite_figure, :clf, :clearfig, :overwrite, :reuse) add_aliases(:overwrite_figure, :clf, :clearfig, :overwrite, :reuse)
add_aliases(:xerror, :xerr, :xerrorbar) add_aliases(:xerror, :xerr, :xerrorbar)
add_aliases(:yerror, :yerr, :yerrorbar, :err, :errorbar) add_aliases(:yerror, :yerr, :yerrorbar, :err, :errorbar)
add_aliases(:zerror, :zerr, :zerrorbar)
add_aliases(:quiver, :velocity, :quiver2d, :gradient, :vectorfield) add_aliases(:quiver, :velocity, :quiver2d, :gradient, :vectorfield)
add_aliases(:normalize, :norm, :normed, :normalized) add_aliases(:normalize, :norm, :normed, :normalized)
add_aliases(:show_empty_bins, :showemptybins, :showempty, :show_empty) add_aliases(:show_empty_bins, :showemptybins, :showempty, :show_empty)

View File

@ -211,7 +211,7 @@ const _base_supported_args = [
:seriestype, :seriestype,
:seriescolor, :seriesalpha, :seriescolor, :seriesalpha,
:smooth, :smooth,
:xerror, :yerror, :xerror, :yerror, :zerror,
:subplot, :subplot,
:x, :y, :z, :x, :y, :z,
:show, :size, :show, :size,

View File

@ -159,7 +159,7 @@ end
function _add_errorbar_kw(kw_list::Vector{KW}, kw::AKW) function _add_errorbar_kw(kw_list::Vector{KW}, kw::AKW)
# handle error bars by creating new recipedata data... these will have # handle error bars by creating new recipedata data... these will have
# the same recipedata index as the recipedata they are copied from # the same recipedata index as the recipedata they are copied from
for esym in (:xerror, :yerror) for esym in (:xerror, :yerror, :zerror)
if get(kw, esym, nothing) !== nothing if get(kw, esym, nothing) !== nothing
# we make a copy of the KW and apply an errorbar recipe # we make a copy of the KW and apply an errorbar recipe
errkw = copy(kw) errkw = copy(kw)

View File

@ -1012,49 +1012,62 @@ function error_zipit(ebar)
end end
end end
function error_coords(xorig, yorig, ebar) error_tuple(x) = x, x
# init empty x/y, and zip errors if passed Tuple{Vector,Vector} error_tuple(x::Tuple) = x
x, y = Array{float_extended_type(xorig)}(undef, 0), Array{Float64}(undef, 0)
# for each point, create a line segment from the bottom to the top of the errorbar function error_coords(errorbar, errordata, otherdata...)
for i = 1:max(length(xorig), length(yorig)) ed = Vector{float_extended_type(errordata)}(undef, 0)
xi = _cycle(xorig, i) od = [Float64[] for _ in otherdata]
yi = _cycle(yorig, i) for (i, edi) in enumerate(errordata)
ebi = _cycle(ebar, i) for (j, odj) in enumerate(otherdata)
nanappend!(x, [xi, xi]) odi = _cycle(odj, i)
e1, e2 = if istuple(ebi) nanappend!(od[j], [odi, odi])
first(ebi), last(ebi)
elseif isscalar(ebi)
ebi, ebi
else
error("unexpected ebi type $(typeof(ebi)) for errorbar: $ebi")
end end
nanappend!(y, [yi - e1, yi + e2]) e1, e2 = error_tuple(_cycle(errorbar, i))
nanappend!(ed, [edi - e1, edi + e2])
end end
x, y return (ed, od...)
end end
# we will create a series of path segments, where each point represents one # we will create a series of path segments, where each point represents one
# side of an errorbar # side of an errorbar
@recipe function f(::Type{Val{:yerror}}, x, y, z)
error_style!(plotattributes)
markershape := :hline
plotattributes[:x], plotattributes[:y] = error_coords(
plotattributes[:x],
plotattributes[:y],
error_zipit(plotattributes[:yerror]),
)
()
end
@deps yerror path
@recipe function f(::Type{Val{:xerror}}, x, y, z) @recipe function f(::Type{Val{:xerror}}, x, y, z)
error_style!(plotattributes) error_style!(plotattributes)
markershape := :vline markershape := :vline
plotattributes[:y], plotattributes[:x] = error_coords( xerr = error_zipit(plotattributes[:xerror])
plotattributes[:y], if z === nothing
plotattributes[:x], plotattributes[:x], plotattributes[:y] = error_coords(xerr, x, y)
error_zipit(plotattributes[:xerror]), else
) plotattributes[:x], plotattributes[:y], plotattributes[:z] =
error_coords(xerr, x, y, z)
end
()
end
@deps xerror path
@recipe function f(::Type{Val{:yerror}}, x, y, z)
error_style!(plotattributes)
markershape := :hline
yerr = error_zipit(plotattributes[:yerror])
if z === nothing
plotattributes[:y], plotattributes[:x] = error_coords(yerr, y, x)
else
plotattributes[:y], plotattributes[:x], plotattributes[:z] =
error_coords(yerr, y, x, z)
end
()
end
@deps yerror path
@recipe function f(::Type{Val{:zerror}}, x, y, z)
error_style!(plotattributes)
markershape := :hline
if z !== nothing
zerr = error_zipit(plotattributes[:zerror])
plotattributes[:z], plotattributes[:x], plotattributes[:y] =
error_coords(zerr, z, x, y)
end
() ()
end end
@deps xerror path @deps xerror path