From 61e34b7ef87d13a30e327e5b311db09a28e6c6a5 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 8 Apr 2016 11:52:02 -0400 Subject: [PATCH] ribbons; changed errorbar to yerror and added xerror --- src/args.jl | 12 +++++++++--- src/backends/supported.jl | 20 +++++++++++++++----- src/recipes.jl | 35 ++++++++++++++++++----------------- src/series_args.jl | 17 +++++++++++++---- 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/src/args.jl b/src/args.jl index a6e421c7..98bba5b7 100644 --- a/src/args.jl +++ b/src/args.jl @@ -145,7 +145,9 @@ _seriesDefaults[:zcolor] = nothing # value for color scale # _seriesDefaults[:nlevels] = 15 _seriesDefaults[:levels] = 15 _seriesDefaults[:orientation] = :vertical -_seriesDefaults[:errorbar] = nothing +_seriesDefaults[:xerror] = nothing +_seriesDefaults[:yerror] = nothing +_seriesDefaults[:ribbon] = nothing const _plotDefaults = KW() @@ -325,8 +327,12 @@ end :clearfig => :overwrite_figure, :overwrite => :overwrite_figure, :reuse => :overwrite_figure, - :err => :errorbar, - :error => :errorbar, + :err => :yerror, + :errorbar => :yerror, + :xerr => :xerror, + :xerrorbar => :xerror, + :yerr => :yerror, + :yerrorbar => :yerror, ) # add all pluralized forms to the _keyAliases dict diff --git a/src/backends/supported.jl b/src/backends/supported.jl index 069971d0..ea8023db 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -77,7 +77,9 @@ supportedArgs(::GadflyBackend) = [ :grid, # :surface, :levels, - :errorbar, + :xerror, + :yerror, + :ribbon, :orientation, ] supportedAxes(::GadflyBackend) = [:auto, :left] @@ -166,7 +168,9 @@ supportedArgs(::PyPlotBackend) = [ :linealpha, :markeralpha, :overwrite_figure, - :errorbar, + :xerror, + :yerror, + :ribbon, :orientation, ] supportedAxes(::PyPlotBackend) = _allAxes @@ -242,7 +246,9 @@ supportedArgs(::GRBackend) = [ :fillalpha, :linealpha, :markeralpha, - :errorbar, + :xerror, + :yerror, + :ribbon, :orientation, ] supportedAxes(::GRBackend) = _allAxes @@ -566,7 +572,9 @@ supportedArgs(::PlotlyBackend) = [ :legendfont, :grid, :levels, - :errorbar, + :xerror, + :yerror, + :ribbon, :orientation, ] supportedAxes(::PlotlyBackend) = [:auto, :left] @@ -638,7 +646,9 @@ supportedArgs(::PlotlyJSBackend) = [ :legendfont, :grid, :levels, - :errorbar, + :xerror, + :yerror, + :ribbon, :orientation, ] supportedAxes(::PlotlyJSBackend) = [:auto, :left] diff --git a/src/recipes.jl b/src/recipes.jl index a9939a85..737ba606 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -140,28 +140,15 @@ end # --------------------------------------------------------------------------- # Error Bars - -# we will create a series of path segments, where each point represents one -# side of an errorbar -function apply_series_recipe(d::KW, ::Type{Val{:errorbar}}) +function error_style!(d::KW) d[:linetype] = :path - d[:markershape] = isvertical(d) ? :hline : :vline d[:linecolor] = d[:markerstrokecolor] d[:linewidth] = d[:markerstrokewidth] d[:label] = "" +end - # to simplify: when orientation is horizontal, x/y are swapped - ebar = pop!(d, :errorbar) - xorig, yorig = d[:x], d[:y] - if !isvertical(d) - xorig, yorig = yorig, xorig - end - # dumpdict(d, "err", true) - # @show isvertical(d) xorig yorig ebar - - # now assume vertical orientation +function error_coords(xorig, yorig, ebar) x, y = zeros(0), zeros(0) - w = 0.3 * mean(diff(x)) for i = 1:max(length(xorig), length(yorig)) # create a line segment from the bottom to the top of the errorbar xi = get_mod(xorig, i) @@ -170,8 +157,22 @@ function apply_series_recipe(d::KW, ::Type{Val{:errorbar}}) nanappend!(x, [xi, xi]) nanappend!(y, [yi - ebi, yi + ebi]) end + x, y +end - d[:x], d[:y] = isvertical(d) ? (x, y) : (y, x) +# we will create a series of path segments, where each point represents one +# side of an errorbar +function apply_series_recipe(d::KW, ::Type{Val{:yerror}}) + error_style!(d) + d[:markershape] = :hline + d[:x], d[:y] = error_coords(d[:x], d[:y], d[:yerror]) + KW[d] +end + +function apply_series_recipe(d::KW, ::Type{Val{:xerror}}) + error_style!(d) + d[:markershape] = :vline + d[:y], d[:x] = error_coords(d[:y], d[:x], d[:xerror]) KW[d] end diff --git a/src/series_args.jl b/src/series_args.jl index 1777ff7e..1449648c 100644 --- a/src/series_args.jl +++ b/src/series_args.jl @@ -151,10 +151,19 @@ function build_series_args(plt::AbstractPlot, kw::KW) #, idxfilter) d[:fillrange] = map(d[:fillrange], d[:x]) end - # handle error bars and ribbons - if get(d, :errorbar, nothing) != nothing - # we make a copy of the KW and apply an errorbar recipe - append!(ret, apply_series_recipe(copy(d), Val{:errorbar})) + # handle error bars + for esym in (:xerror, :yerror) + if get(d, esym, nothing) != nothing + # we make a copy of the KW and apply an errorbar recipe + append!(ret, apply_series_recipe(copy(d), Val{esym})) + end + end + + # handle ribbons + if get(d, :ribbon, nothing) != nothing + # append!(ret, apply_series_recipe(copy(d), Val{:ribbon})) + rib = d[:ribbon] + d[:fillrange] = (d[:y] - rib, d[:y] + rib) end