ribbons; changed errorbar to yerror and added xerror

This commit is contained in:
Thomas Breloff 2016-04-08 11:52:02 -04:00
parent 3c3078875a
commit 61e34b7ef8
4 changed files with 55 additions and 29 deletions

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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