diff --git a/src/pipeline.jl b/src/pipeline.jl index 4e4e9521d..c987f31f2 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -98,14 +98,18 @@ end function _add_errorbar_kw(kw_list::Vector{KW}, kw::AKW) # handle error bars by creating new recipedata data... these will have # the same recipedata index as the recipedata they are copied from - for esym in (:xerror, :yerror, :zerror) - if get(kw, esym, nothing) !== nothing - # we make a copy of the KW and apply an errorbar recipe - errkw = copy(kw) - errkw[:seriestype] = esym - errkw[:label] = "" - errkw[:primary] = false - push!(kw_list, errkw) + st = get(kw, :seriestype, :none) + errors = (:xerror, :yerror, :zerror) + if st ∉ errors + for esym in errors + if get(kw, esym, nothing) !== nothing + # we make a copy of the KW and apply an errorbar recipe + errkw = copy(kw) + errkw[:seriestype] = esym + errkw[:label] = "" + errkw[:primary] = false + push!(kw_list, errkw) + end end end end @@ -138,7 +142,7 @@ RecipesPipeline.get_axis_limits(plt::Plot, letter) = axis_limits(plt[1], letter, ## Plot recipes -RecipesPipeline.type_alias(plt::Plot) = get(_typeAliases, st, st) +RecipesPipeline.type_alias(plt::Plot, st) = get(_typeAliases, st, st) ## Plot setup @@ -153,7 +157,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l err_inds = findall(kw -> get(kw, :seriestype, :path) in (:xerror, :yerror, :zerror), kw_list) for ind in err_inds - if get(kw_list[ind - 1], :seriestype, :path) === :scatter + if ind > 1 && get(kw_list[ind - 1], :seriestype, :path) === :scatter tmp = copy(kw_list[ind]) kw_list[ind] = copy(kw_list[ind - 1]) kw_list[ind - 1] = tmp diff --git a/src/recipes.jl b/src/recipes.jl index 59f98e8c2..c4248a76f 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -1134,7 +1134,7 @@ end # --------------------------------------------------------------------------- # Error Bars -function error_style!(plotattributes::AKW) +@attributes function error_style!(plotattributes::AKW) # errorbar color should soley determined by markerstrokecolor if haskey(plotattributes, :marker_z) reset_kw!(plotattributes, :marker_z) @@ -1156,12 +1156,12 @@ function error_style!(plotattributes::AKW) msc end - plotattributes[:seriestype] = :path - plotattributes[:markerstrokecolor] = msc - plotattributes[:markercolor] = msc - plotattributes[:linecolor] = msc - plotattributes[:linewidth] = plotattributes[:markerstrokewidth] - plotattributes[:label] = "" + seriestype := :path + markerstrokecolor --> msc + markercolor --> msc + linecolor --> msc + linewidth --> plotattributes[:markerstrokewidth] + label --> "" end # if we're passed a tuple of vectors, convert to a vector of tuples @@ -1194,7 +1194,7 @@ clamp_to_eps!(ary) = (replace!(x -> x <= 0.0 ? Base.eps(Float64) : x, ary); noth @recipe function f(::Type{Val{:xerror}}, x, y, z) error_style!(plotattributes) - markershape := :vline + markershape --> :vline xerr = error_zipit(plotattributes[:xerror]) if z === nothing plotattributes[:x], plotattributes[:y] = error_coords(xerr, x, y) @@ -1211,7 +1211,7 @@ end @recipe function f(::Type{Val{:yerror}}, x, y, z) error_style!(plotattributes) - markershape := :hline + markershape --> :hline yerr = error_zipit(plotattributes[:yerror]) if z === nothing plotattributes[:y], plotattributes[:x] = error_coords(yerr, y, x) @@ -1228,7 +1228,7 @@ end @recipe function f(::Type{Val{:zerror}}, x, y, z) error_style!(plotattributes) - markershape := :hline + markershape --> :hline if z !== nothing zerr = error_zipit(plotattributes[:zerror]) plotattributes[:z], plotattributes[:x], plotattributes[:y] = diff --git a/src/shorthands.jl b/src/shorthands.jl index 83bb49a74..2ef0b1143 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -487,6 +487,16 @@ for letter in ("x", "y", "z") $(Symbol(letter, :grid!))(plt::PlotOrSubplot, args...; kw...) = plot!(plt; $(Symbol(letter, :grid)) = args, kw...) export $(Symbol(letter, :grid!)) + + """ + $($letter)error(x, y [, z]; $($letter)error = vals) + $($letter)error!(x, y [, z]; $($letter)error = vals) + + Create or add a series of $($letter)errorbars at the positions defined by `x`, `y` and `z` with the lenghts defined in `vals`. + + Markerstrokecolor will color the whole errorbars if not specified otherwise. + """ + @shorthands $(Symbol(letter, :error)) end end diff --git a/test/test_recipes.jl b/test/test_recipes.jl index 356e02af1..7c03e29c2 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -65,3 +65,16 @@ end @test Plots.seriestype_supported(Plots.UnicodePlotsBackend(), :hspan) === :recipe @test Plots.seriestype_supported(Plots.NoBackend(), :line) === :no end + +@testset "error bars" begin + x = y = 1:10 + yerror = fill(1, length(y)) + xerror = fill(0.2, length(x)) + p = Plots.xerror(x, y; xerror, linestyle = :solid) + plot!(p, x, y; linestyle = :dash) + yerror!(p, x, y; yerror, linestyle = :dot) + @test length(p.series_list) == 3 + @test p[1][1][:linestyle] == :solid + @test p[1][2][:linestyle] == :dash + @test p[1][3][:linestyle] == :dot +end